Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question