Can I use nested type in Scala generic function? -
how can use nested type in scala generic function ? i'd implement this
implicit def basicdblist2list[list[a]](value : basicdblist) = value.tolist.asinstanceof[list[a]]
compiler gives following error:
scala: not found: type implicit def basicdblist2list[list[a]](value : basicdblist) = value.tolist.asinstanceof[list[a]] ^
when write:
implicit def basicdblist2list[list[a]](value: basicdblist) = ...
... doesn't mean think means. you're declaring new type parameter called list
, not referring existing list
trait in library! you're declaring newly-defined list
type requires type parameter, you've called a
, can't reference it.
what meant was:
implicit def basicdblist2list[a](value: basicdblist): list[a] = ...
... says that, type a
, can convert basicdblist
list[a]
.
this sketchy code, though, 2 reasons:
- what type
basicdblist
class contain? not possiblea
. you'llclasscastexception
@ runtime. - why want implicit conversion
basicdblist
list[a]
? that's bad idea.
Comments
Post a Comment