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

Reflection API exposes bridge methods from interfaces (Java 8) #9112

Open
scabug opened this issue Jan 22, 2015 · 1 comment
Open

Reflection API exposes bridge methods from interfaces (Java 8) #9112

scabug opened this issue Jan 22, 2015 · 1 comment
Milestone

Comments

@scabug
Copy link

scabug commented Jan 22, 2015

In Java 8, when an interface overrides a method from another interface and narrows the method's return type, additional bridge method with original return type is generated.
This bridge method doesn't seem to be properly filtered by Scala reflection API, e.g. Symbol's overrides method.

Example:

public interface DynamicGetter {
    public Object get(String property);
}

public interface Base extends DynamicGetter {
    @Override
    public Base get(String property);
}

public class Klass implements Base {
    @Override
    public Klass get(String property) {
        return this;
    }
}

Manifestation:

$ scala
Welcome to Scala version 2.11.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> val g = typeOf[Klass].member(TermName("get"))
g: $r.intp.global.Symbol = method get

scala> g.overrides
res0: List[$r.intp.global.Symbol] = List(value get, method get)

scala> g.overrides.head.alternatives.map(_.typeSignature)
res2: List[$r.intp.global.Type] = List((x$1: String)Base, (x$1: String)Object) 

scala> typeOf[Base].member(TermName("get"))
res3: $r.intp.global.Symbol = method get

Original discussion: https://groups.google.com/forum/?fromgroups=#!topic/scala-user/IeD2siVXyss

@scabug
Copy link
Author

scabug commented Jan 22, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9112?orig=1
Reporter: @ghik
Affected Versions: 2.11.4, 2.11.5

@SethTisue SethTisue added this to the Backlog milestone Mar 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants