Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch problem when trying to get annotation from returnType of method (was issue 715) #987

Closed
dholzenburg opened this issue Jul 4, 2018 · 1 comment
Assignees

Comments

@dholzenburg
Copy link

dholzenburg commented Jul 4, 2018

Hi,

I used your latest testcase in issue #715 and that worked fine. I made a minor modification and now it works with javac, but fails with j2objc.

Sorry to bother you again with this one ;-) This issue is not a blocker for me.

BTW: I like j2objc very much and I really appreciate your efforts. Besides this minor issue j2objc works very well. Thank you!

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface SomeAnnotation {

  String value() default "";
}
import java.lang.reflect.Method;

@SomeAnnotation("type")
public class SomeClass {

  public static void main(String... args) throws NoSuchMethodException {
    final Method method = SomeClass.class.getMethod("someMethod");

    //works
    System.out.println("annotation on method: " + method.getAnnotation(SomeAnnotation.class));

    //works
    System.out.println("1: annotation on return type: "
      + method.getReturnType().getAnnotation(SomeAnnotation.class));

    //fails
    final SomeAnnotation someAnnotation = method.getReturnType().getAnnotation(SomeAnnotation.class);
    System.out.println("2: annotation on return type: " + someAnnotation);
  }

  @SomeAnnotation("method")
  public SomeClass someMethod() {
    return null;
  }
}

Output:

$ javac SomeClass.java SomeAnnotation.java 
$ java SomeClass
annotation on method: @SomeAnnotation(value=method)
1: annotation on return type: @SomeAnnotation(value=type)
2: annotation on return type: @SomeAnnotation(value=type)
$ /usr/local/j2objc/2.1.1/j2objc SomeClass.java SomeAnnotation.java 
SomeClass.java:18: error: incompatible types: java.lang.annotation.Annotation cannot be converted to SomeAnnotation
    final SomeAnnotation someAnnotation = method.getReturnType().getAnnotation(SomeAnnotation.class);
tomball pushed a commit that referenced this issue Jul 31, 2018
…returnType of method (was issue 715)

Matching signature defined in:
https://android.googlesource.com/platform/libcore/+/android-7.1.2_r36/ojluni/src/main/java/java/lang/reflect/Method.java

	Change on 2018/07/13 by antoniocortes <antoniocortes@google.com>

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=204470786
@tomball
Copy link
Collaborator

tomball commented Jul 31, 2018

Fixed in current source.

@tomball tomball closed this as completed Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants