在Java 6中,我能够使用:
public static <T, UK extends T, US extends T> T getCountrySpecificComponent(UK uk, US us) {
Country country = CountryContext.getCountry();
if (country == Country.US) {
return us;
} else if (country == Country.UK) {
return uk;
} else {
throw new IllegalStateException("Unhandled country returned: "+country);
}
}
Run Code Online (Sandbox Code Playgroud)
使用这些存储库:
public interface Repository{
List<User> findAll();
}
public interface RepositoryUS extends Repository{}
public interface RepositoryUK extends Repository{}
Run Code Online (Sandbox Code Playgroud)
使用这些时:
RepositoryUK uk = ...
RepositoryUS us = ...
Run Code Online (Sandbox Code Playgroud)
这行在Java6中编译但在Java7中失败(错误找不到符号 - 因为编译器在类Object上查找findAll())
List<User> users = …Run Code Online (Sandbox Code Playgroud) 我想知道一个类中给定对象的名称
class B {
abstract class F{
def name = getClass.getSimpleName
}
object FI extends F
}
val b = new B
println(b.FI)
Run Code Online (Sandbox Code Playgroud)
使用Scala 2.9.1,它打印B $ FI $
使用Scala 2.9.2,它打印FI $
我真正想要的是"FI".获取FI的最佳方法是什么,并确保它在未来版本的scala中不会改变?是否有一些反思支持来帮助我?