Scala方法,其中第二个参数的类型等于第一个参数的泛型类型的一部分

Ing*_*her 5 generics scala scala-2.8

我想在Scala中创建一个特定的泛型方法.它需要两个参数.第一种是通用Java接口的类型(它来自JPA条件查询).它目前看起来像这样:

def genericFind(attribute:SingularAttribute[Person, _], value:Object) {
  ...
}

// The Java Interface which is the type of the first parameter in my find-method:
public interface SingularAttribute<X, T> extends Attribute<X, T>, Bindable<T>
Run Code Online (Sandbox Code Playgroud)

现在我想实现以下目的: value当前是java.lang.Object类型.但我想让它更具体.值必须与第一个参数中的占位符"_"具有相同的类型(因此代表Java接口中的"T").

这是不可能的,怎么样?

BTW对不起这个愚蠢的问题标题(有什么建议吗?)

编辑: 添加了一个可以使问题更清晰的附加示例:

// A practical example how the Scala method could be called 

// Java class:
public class Person_ {
  public static volatile SingularAttribute<Person, Long> id;
}

// Calling the method from Scala:
genericFind(Person_.id, Long)
Run Code Online (Sandbox Code Playgroud)

RoT*_*oRa 9

在我的头脑中(我仍然从Scala开始):

def genericFind[T](attribute:SingularAttribute[Person, T], value:T) {
  ...
}
Run Code Online (Sandbox Code Playgroud)