Menu

Get *dynamic* type of field reference?

Developers
widheg
2009-11-09
2012-10-08
  • widheg

    widheg - 2009-11-09

    Hi all!
    How do I retrieve the dynamic type of a field reference?
    In comparison, to retrieve the static type of FieldReference 'x' I have:

    ReferencePrefix refPrefix = x.getReferencePrefix();
    if (refPrefix != null) {
    Type type = sc.getSourceInfo().getType(refPrefix);

    }

    The same question applies also for a MethodReference.
    Thanks for any help or hints!

     
  • Tobias Gutzmann

    Tobias Gutzmann - 2009-11-09

    Hej,

    do (1) you mean the type at runtime? Or (2) simply the type of a
    (Field|Method)Reference if it does not have a prefix?

    (1) not at all with Recoder, as it is a framework for static analysis and
    metaprogramming ;)
    (2) sc.getSourceInfo().getMethod(x).getContainingClassType().
    Note, before Java 5 a member reference that is not prefixed would have to come
    from the current type (possibly inherited). That is NOT the case any more, due
    to static imports.

    /Tobias

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.