본문 바로가기

Backend/Java

Polymorphism

반응형

In Object Oriented Programming, it is possible to use one interface to implement different types and this feature is called polymorphism. Think of it as a form that can take various values. So polymorphism is just a functionality that allows different values with one class.

Runtime Type VS Compile-time Type Typing

As mentioned polymorphism enables us to use one class to implement different values, this is possible because the runtime types and compile-time types are different. Compile-time type usually comes to the left side of the assignment while the runtime type comes to the right side of the assignment.

Local Variable Type Inferent (LVTI) - var

var was introduced in Java 10 and it allows us to define a variable regardless of the type. Some of the limitations are as follows.

1. Cannot be used as class fields

2. Cannot be used as method signatures, parameters, or return types

3. Value must be assigned for type inference (in the same sense, null cannot be assigned)

 

728x90
반응형

'Backend > Java' 카테고리의 다른 글

Springboot - Sending Emails  (0) 2024.02.10
Method Overriding VS Overloading  (1) 2023.12.31
java: error: release version 21 not supported  (0) 2023.12.30
Lombok  (0) 2023.12.29
Inheritance  (0) 2023.12.28