G
G
go2goj2019-12-03 19:39:45
Java
go2goj, 2019-12-03 19:39:45

Are object types in java determined at runtime?

Are object types determined at runtime? Why can't it be compiled like this then? (The type of the object is still unknown, sort of).

class Solution {
  public static void main(String[] args) {
    String object = new Solution(); //	ошибка компиляции (несоответствие типов)
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2019-12-03
@go2goj

No, Java has static typing. The types are known at compile time. In your example, the types of the object and variable are known and do not match (and the type of the object cannot be cast to the type of the variable).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question