(Random can't be used in a static method) ?????

11 views
Skip to first unread message

Shawn Brown

unread,
Jul 22, 2010, 6:32:16 AM7/22/10
to Google-We...@googlegroups.com
is this as expected (Random can't be used in a static method) ?????

public static void test() { // static method
Log.info("random int "+Random.nextInt(6));
}

----->throws a java.lang.UnsatisfiedLinkError:
com.google.gwt.user.client.Random.nextInt(I)I

BUT ...

com.google.gwt.user.client.Random;

public void test() { // non-static method
Log.info("random int: "+Random.nextInt(6));


----->IS OK!!!


--------- a l s o ----------


java.util.Random random = new Random;

public static void test() { // static method
Log.info("random int "+random.nextInt(6));
}

----->throws a nullpointer

BUT ...

public void test() { // not static
Log.info("random int "+random.nextInt(6));
}

----->is fine!!!

Aaaaaaah. Damn, I just re-factored for hours and made a static
reusable utility class...


Why can't I do that by the way?


Shawn

Shawn Brown

unread,
Jul 22, 2010, 6:50:38 AM7/22/10
to Google-We...@googlegroups.com
Actually if com.google.gwt.user.client.Random is in a static method
called by a static method it fails.

com.google.gwt.user.client.Random in a static method called by a
non-static method works fine.

Seems a little flakey to me but ... I'm probably just not as smart as you!

Shawn

cokol

unread,
Jul 22, 2010, 8:04:30 AM7/22/10
to Google Web Toolkit
watch out! you cannot make new Random() on GWT's type otherwise your
IDE would pull in Javas implementation, so only Random.getNext() works

make sure your Random is imported from com.google rather than
java.util
Reply all
Reply to author
Forward
0 new messages