Bridge metodlar derleyici tarafından üretilir.
- Generic kodlarda Object parametre alan metodlara erişim için üretirlir. Bunlar bridge denir.
- non-public class'ın public metoduna erişim içi üretilir. Bunlar bridge denir.
Açıklaması şöyle
- in case of non-public classes a bridge method will be created (so that reflection would work)- in case of generics an erased bridge method will be created (so that erased calls would work)
Örnek - generics
Elimizde şöyle bir kodd olsun
interface WithGeneric<T> {
  public WithGeneric<T> self(T s);
}
public class Impl implements WithGeneric<String> {
  @Override
  public WithGeneric<String> self(String s) {
    return null;
  }
}Impl sınıfında iki tane metod bulunurr
public WithGeneric<String> self(String) {...}
public WithGeneric self(Object) {...}Örnek - non-public class'ın public metodu
Elimizde şöyle bir kod olsun
static class A {
    public String foo() { return null; }
}
public static class B extends A {}... will generate a foo method with ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC. On the other hand if you make A public, such a method will not be generated, the reason should be obvious,
Hiç yorum yok:
Yorum Gönder