1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817
- Site Admin
- Posts: 9425
- Joined: Fri Sep 10, 2010 9:26 pm
What it is trying to say is that even if the reference resolves to null at runtime, it doesn't matter because the JVM doesn't need the object reference to access static members anyway. The compiler replaces getDatabase().url with DatabaseWrapper.url!Note the method signature. It returns a reference to an object of class DatabaseWrapper. Thus, getDatabase().url means we are accessing url field of the object returned by the method. Now, since the class of the object returned by the method is DatabaseWrapper and the field url is a static field of the class, the compiler creates the instruction for the JVM to access this field directly using the class reference instead of the object reference returned by the method at runtime. Thus, the JVM does not need to depend on the actual object returned by the method at run time to access url. So even if the method returns null at run time, it doesn't matter because the JVM doesn't even access the reference returned by the method.
Users browsing this forum: No registered users and 1 guest