How to call a generic method with an anonymous type involving generics?
- by Alex Black
I've got this code that works:
def testTypeSpecialization = {
class Foo[T]
def add[T](obj: Foo[T]): Foo[T] = obj
def addInt[X <% Foo[Int]](obj: X): X = {
add(obj)
obj
}
val foo = addInt(new Foo[Int] {
def someMethod: String = "Hello world"
})
assert(true)
}
But, I'd like to write it like…