I am trying to do what is mentioned below but am struggling with the
object side of things for my particular case. This all relates back
to trying to auto-generate some classes that I posted back a while ago
on. I would love to generate 1 file that has the trait and the object
in it that I then
Isn't this really a matter of type casting, and asInstanceOf is just
Scala's
way of doing this. It's always best if you don't have to downcast your
objects, but sometimes its unavoidable.
Glenn...
On Sep 3, 10:29 am, glenn wrote:
> I'm not sure of what the exact problem is. I created an Address
I'm not sure of what the exact problem is. I created an Address trait
that
I couple with a number of mapper classes.
trait Address[OwnerType <: KeyedMapper[Long, OwnerType]]{
def owner = this.asInstanceOf[OwnerType]
Where exactly does this construct break down?
Glenn...
On Sep 3, 7:55
jon suggested to me the way to avoid both explicit type parameter and
asinstance of:
trait Timestamp[MapperType <: TimeStamp[MapperType]] extends Mapper
[MapperType] {
self:MapperType =>
object xdatetime extends MappedDateTime(this)
// all sorts of utility functions for dealing with timestamps
You could also do this:
trait HasCreated [T <: HasCreated[T]] extends KeyedMapper[Long, T] {
self: T =>
object created_at extends MappedDateTime(this)
}
//mix into your meta object:
trait HasCreatedMetaMapper[T <: HasCreated[T]] {
self: T with LongKeyedMetaMapper[T] =>
import java.ut
As an alternative to asInstanceOf you could use explicit type
parameter in MappedField creation:
self:MapperType =>
object xdatetime extends MappedDateTime[MapperType](this)
On 3 Set, 09:19, Giuseppe Fogliazza wrote:
> Unfortunately you cannot escape from asInstanceOf . Forcing
> self:MapperTyp
Unfortunately you cannot escape from asInstanceOf . Forcing
self:MapperType the type of "this" will be TimeStamp with MapperType
violating the constraint for the type of the first parameter of
MappedDateTime :T <: Mapper[T].
Regards
Giuseppe
On 3 Set, 07:08, Naftoli Gugenheim wrote:
> So I gues
So I guess you can't escape the asInstanceOf. Can you successfully give the
trait a self-type of this: MapperType =>, or declare it to extend
Mapper[MapperType], without running into problems elsewhere?
-
harryh wrote:
I've been handling this with traits,
I've been handling this with traits, for example I have something like
so:
trait Timestamp[MapperType <: Mapper[MapperType]] {
object xdatetime extends MappedDateTime[MapperType](this.asInstanceOf
[MapperType])
// all sorts of utility functions for dealing with timestamps
}
Then I can do
c