GWT Generator

2 views
Skip to first unread message

Ammar Belakhel

unread,
Oct 5, 2009, 4:18:50 PM10/5/09
to Google Web Toolkit
Hi,

I am facing a problem with the JType class, I want to determine if the
return type of a method is an instance of the String class.

This is my solution:

JMethod method = ...;
JType returnType = method.getReturnType();
if (returnType instanceof JClassType) {
JClassType type = (JClassType) returnType;
String name = type.getName();
if (name.equals(String.class.getName())) {
// ....
}
}

Is there an efficient way to determine if the return type of method is
an instance of given class?

Thanks.

Thomas Broyer

unread,
Oct 6, 2009, 12:37:42 PM10/6/09
to Google Web Toolkit
Use the TypeOracle's findType or getType method and then compare the
JClassType instances for equality:

JClassType javaLangString = oracle.findType("java.lang.String");
...
if (returnType == javaLangString) { ... }

(note: you can use reference equality, because TypeOracle guarantees
JClassType for a given class are singletons)

Ammar Belakhel

unread,
Nov 7, 2009, 8:14:38 AM11/7/09
to Google Web Toolkit
Thank you very much.
Reply all
Reply to author
Forward
0 new messages