Tuesday, October 6, 2009

Re: GWT Generator

On 5 oct, 22:18, Ammar Belakhel <ammar.belak...@gmail.com> wrote:
> 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?

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)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate