How to access static final variable of an inner class of java

92 views
Skip to first unread message

Zang MingJie

unread,
Sep 18, 2012, 4:51:39 AM9/18/12
to scala...@googlegroups.com
Hi,

I encounter a problem when try to access static final variable of an inner class of java

Sample code in JAVA:

public class Out {
public class In {
public static final int V = 10;
}
}

How to access Out.In.V in scala ?

Kevin Wright

unread,
Sep 18, 2012, 4:59:02 AM9/18/12
to Zang MingJie, scala...@googlegroups.com
Even in pure Java, that looks odd to me - because In isn't defined as a static class.
Have you tried accessing `instanceOfOut.In.V`?

Zang MingJie

unread,
Sep 18, 2012, 5:02:40 AM9/18/12
to scala...@googlegroups.com, Zang MingJie


On Tuesday, September 18, 2012 4:59:07 PM UTC+8, Kevin Wright wrote:
Even in pure Java, that looks odd to me - because In isn't defined as a static class.
Yes, java sucks, that's why I got scala
 
Have you tried accessing `instanceOfOut.In.V`?
I can access V via Out.In.V w/o using any instance in java, and I need equivalent method in scala

Som Snytt

unread,
Sep 18, 2012, 12:50:58 PM9/18/12
to Zang MingJie, scala...@googlegroups.com
Null is not an instance:

println(null.asInstanceOf[Out].In.V)
Reply all
Reply to author
Forward
0 new messages