This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Abstract types and Classmanifest

3 replies
edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
Dear user,
I am meeting a recurrent problem with Scala.

I have written a base class with an abstract type,

such as type K<:AnyRef and an abstract method returning a List[K].


Inside my base class, I would need to do List.toArray, but the compiler produces the following output.

error: could not find implicit value for evidence parameter of type ClassManifest[CurveMockTest.this.K]


I tried to change the type K<:AnyRef:ClassManifest but that didn't work.


Can you please help me?

Best Regards
Peter 2
Joined: 2011-02-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Abstract types and Classmanifest

Hi Edmondo,

you are on the right track with Manifest. But
class T[K<:AnyRef:ClassManifest]
being working code it's difficult to tell you what you are missing.
Here again, full, boiled-down code is advisable.

Peter

edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
Re: Re: Abstract types and Classmanifest
Dear Peter,

I am not using a generic parameter for the class, but an abstract type and that leads to the error....

Best Regards

2011/10/11 Sonnenschein <peter [dot] empen [at] arcor [dot] de>
Hi Edmondo,

you are on the right track with Manifest. But
class T[K<:AnyRef:ClassManifest]
being working code it's difficult to tell you what you are missing.
Here again, full, boiled-down code is advisable.

Peter

Peter 2
Joined: 2011-02-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Abstract types and Classmanifest

Sorry, I have missunderstood. Your problem is:

trait T{
type K<:AnyRef
def list: List[K]
def array=list.toArray
}

Try instead:

def array[X>:K:Manifest]=list.toArray[X]

Peter

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland