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

Traits and reflection

3 replies
Dustin Whitney
Joined: 2009-02-08,
User offline. Last seen 2 years 32 weeks ago.
I'd love to create an instance of a class using reflection with a given trait.  Anybody know how this is done.

For example, I'd like the following

trait Krunk{}
Class.forName("java.util.Date") with Krunk

Any help is appreciated!

-Dustin
Szymon Jachim
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: Traits and reflection
Traits cocktail can not be prepared during the party.
Unless you are scala-compiler.jar... ;-)

I hope this will help you get the date you want.
Szymon
On Mon, Mar 9, 2009 at 12:50 AM, Dustin Whitney <dustin.whitney@gmail.com> wrote:
I'd love to create an instance of a class using reflection with a given trait.  Anybody know how this is done.

For example, I'd like the following

trait Krunk{}
Class.forName("java.util.Date") with Krunk

Any help is appreciated!

-Dustin



--
ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
Dustin Whitney
Joined: 2009-02-08,
User offline. Last seen 2 years 32 weeks ago.
Re: Re: Traits and reflection
Is that a funny way of saying "no, some form of 'Class.forName("java.util.Date").newInstance with Krunk' is not possible."?

-Dustin

On Mar 9, 2009 4:28am, Szymon Jachim <sjachim@gmail.com> wrote:
> Traits cocktail can not be prepared during the party.
> Unless you are scala-compiler.jar... ;-)
>
>
>
> I hope this will help you get the date you want.
>
>
> Szymon
>
>
> On Mon, Mar 9, 2009 at 12:50 AM, Dustin Whitney dustin.whitney@gmail.com> wrote:
>
> I'd love to create an instance of a class using reflection with a given trait.  Anybody know how this is done.
>
> For example, I'd like the following
>
> trait Krunk{}
> Class.forName("java.util.Date") with Krunk
>
>
>
> Any help is appreciated!
>
> -Dustin
>
>
>
>
> --
> ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>
>
>
Ricky Clarkson
Joined: 2008-12-19,
User offline. Last seen 3 years 2 weeks ago.
Re: Re: Traits and reflection

This is not possible on the JVM without classloader tricks involving
generating bytecode at runtime. Scala doesn't do that.

2009/3/9 :
> Is that a funny way of saying "no, some form of
> 'Class.forName("java.util.Date").newInstance with Krunk' is not possible."?
>
> -Dustin
>
> On Mar 9, 2009 4:28am, Szymon Jachim wrote:
>> Traits cocktail can not be prepared during the party.
>> Unless you are scala-compiler.jar... ;-)
>>
>>
>>
>> I hope this will help you get the date you want.
>>
>>
>> Szymon
>>
>>
>> On Mon, Mar 9, 2009 at 12:50 AM, Dustin Whitney dustin.whitney@gmail.com>
>> wrote:
>>
>> I'd love to create an instance of a class using reflection with a given
>> trait.  Anybody know how this is done.
>>
>> For example, I'd like the following
>>
>> trait Krunk{}
>> Class.forName("java.util.Date") with Krunk
>>
>>
>>
>> Any help is appreciated!
>>
>> -Dustin
>>
>>
>>
>>
>> --
>> ʎɐqǝ uo pɹɐoqʎǝʞ ɐ ʎnq ı ǝɯıʇ ʇsɐן ǝɥʇ sı sıɥʇ
>>
>>
>>

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