Jay Taylor's notes
back to listing indexScala classOf for type parameter: how to call the function and how to restrict with upper type bounds - Stack Overflow
[web search]
I'm working with JAX-RS in Scala and trying to parameterise a call to:
I've been using ClassManifests as per the answer here but have a couple of things I'm still struggling with. As background, my JAX-RS representations all extend a stubbed Representation class:
So far I've defined my function using a ClassManifest like so:
My first question is a bit of a silly one: how do I call this function? I can't figure out what to pass in to get() for the R type and the representation value (the accepted answer to the original question doesn't make this clear). I tried implicit typing as per paradigmatic's comment but the below generates a compile error:
My second question is: is it possible to apply an upper type bound on the R object? In other words, I know that:
Is there a way of bounding this in get()'s ClassManifest type declaration? Many thanks! | |||||||||||||||
| |||||||||||||||
You need to suppress the argument if you don't have any:
To call it:
The type gets between square brackets. | |||||||||
|
About your second question: yes, there is a way to do that:
When you declare type parameters, you may include one lower bound with | ||||
add comment |
an example:
EDIT @paradigmatic is right, in your case it should be
| |||||||||
|