- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Structural types and generics
Dear all,
Is it possible to descrive the bound of a generic argument as a mix of bound on other classes plus some view bounds?
F[A<:B with {def func: Int}] is legal?
Thank you all for your precious help
Best regards
Edmondo
Inviato da BlackBerry(R) Wireless Handheld










Re: Structural types and generics
Edmondo, you may simply write
trait F[A<: {def func: Int}]
Peter
Re: Re: Structural types and generics
I want A to be a subclass of B and to have a certain method...
Best Regards
Edmondo
2012/1/19 Sonnenschein <peter [dot] empen [at] arcor [dot] de>
Re: Re: Structural types and generics
trait B
type C = { def func: Int }
class F[A <: B with C ](a: A) { def doStuff { println(a.func) }}
val b = new B { def func: Int = 42}
val f = new F(b)
f.doStuff
--
Derek Williams
Re: Structural types and generics
Perfect! And if we wanted to omit type C:
class F[A <: B {def func: Int}]
Peter