- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Structural types and generics
Thu, 2012-01-19, 19:02
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
Thu, 2012-01-19, 23:11
#2
Re: Re: Structural types and generics
My use case is slightly different,
I want A to be a subclass of B and to have a certain method...
Best Regards
Edmondo
2012/1/19 Sonnenschein <peter.empen@arcor.de>
I want A to be a subclass of B and to have a certain method...
Best Regards
Edmondo
2012/1/19 Sonnenschein <peter.empen@arcor.de>
Edmondo, you may simply write
trait F[A<: {def func: Int}]
Peter
Thu, 2012-01-19, 23:31
#3
Re: Re: Structural types and generics
How about this:
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
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
Fri, 2012-01-20, 09:31
#4
Re: Structural types and generics
Perfect! And if we wanted to omit type C:
class F[A <: B {def func: Int}]
Peter
Edmondo, you may simply write
trait F[A<: {def func: Int}]
Peter