Scala type (output) problem?

I am developing a REST web service in Scala using JAX-RS Jersey and I get a weird error.

I am trying to create a ContentDisposition object using ContentDisposition.ContentDispositionBuilder .

ContentDisposition.ContentDispositionBuilder has two types of T extends ContentDisposition.ContentDispositionBuilder and V extends ContentDisposition . The type of ContentDisposition returns an instance of the linker.

The code

 val contentDisposition = ContentDisposition.`type`(MediaType.APPLICATION_OCTET_STREAM).build() 

works however

 val contentDisposition = ContentDisposition.`type`(MediaType.APPLICATION_OCTET_STREAM).fileName("dummy").build() 

creates a compiler error

 error: value build is not a member of ?0 val contentDisposition = ContentDisposition.`type`(MediaType.APPLICATION_OCTET_STREAM).fileName("dummy").build() ^ 

(Note that type needs to be enclosed in “quotation marks” because it is a keyword in Scala)

fileName from ContentDispositionBuilder returns an instance of T , so this should work.

I do not understand. Any ideas? By the way, I am using Scala 2.9.0.1.

Update:

It works. But why do I need casting here?

 val contentDisposition = ContentDisposition.`type`(MediaType.APPLICATION_OCTET_STREAM) .fileName("dummy") .asInstanceOf[ContentDisposition.ContentDispositionBuilder[_,_]] .build() 
+7
source share
1 answer

I assume that type inference can only go up to now ... Perhaps you can do this in two lines without making any throws; have you tried this?

 val something=ContentDisposition.`type`(MediaType.APPLICATION_OCTET_STREAM) val contentDisposition=something.fileName("dummy").build() 

or maybe

 val builder=ContentDisposition.`type`(MediaType.APPLICATION_OCTET_STREAM).fileName("dummy") val contentDisposition=builder.build() 
+2
source

All Articles