Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List l = new ArrayList<Number>(); The static type of l is List<Number>? What does that mean?

Tags:

java

List l = new ArrayList<Number>();

The static type of l is List? What does "static type" here mean? I read it in sun's java tutorials

like image 683
Rekha Avatar asked Oct 03 '11 19:10

Rekha


1 Answers

The "static type" of an expression is the type as the compiler thinks of it - the compile-time type. This may be different from the execution-time type of the value of the variable.

For example, consider this:

Object obj = "hello";

The compile-time type (or static type) of the obj variable is java.lang.Object. At execution time, however, the value of obj is a reference to an object of type java.lang.String.

like image 197
Jon Skeet Avatar answered Oct 04 '22 14:10

Jon Skeet