- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
reflection on fields
Fri, 2009-05-29, 17:38
I am trying to pass a Scala object to some Java code,
that calls getFields on the objects class,
and it expects to find certain fields there.
Scala normally compiles fields into a private Java field,
with a getter/setter methods.
Is there any way to get fields of a Scala object to be visible
as fields in via Reflection?
thanks
Daniel
Fri, 2009-05-29, 21:17
#2
Re: reflection on fields
Alex,
Thanks, but that is not quite what I need.
The @BeanProperty annotation adds getter/setter methods
with JavaBeans compliant names.
That makes them bean properties, but not fields.
The Java code I am calling does not use the beans interface,
it just calls getFields on the class and looks in the result for what it wants,
but Scala classes do not have public fields (from Java's point of view).
I suspect that there is no way to get Scala objects to have public java fields,
but I would love to be wrong.
Daniel
On 5/29/09, Alex Boisvert wrote:
> This may help,
> http://scala.sygneca.com/code/defining-bean-properties
>
> On Fri, May 29, 2009 at 9:36 AM, Daniel Mahler wrote:
>
>> I am trying to pass a Scala object to some Java code,
>> that calls getFields on the objects class,
>> and it expects to find certain fields there.
>> Scala normally compiles fields into a private Java field,
>> with a getter/setter methods.
>> Is there any way to get fields of a Scala object to be visible
>> as fields in via Reflection?
>>
>> thanks
>> Daniel
>>
>
Mon, 2009-06-01, 19:37
#3
Re: reflection on fields
I'm guessing this could be for Javaspace Entry objects, which must contain public fields. If not, that's another example of the need for public fields if full Java framework compatibility is a goal. I can smell another annotation.
On Fri, May 29, 2009 at 3:14 PM, Daniel Mahler <dmahler@gmail.com> wrote:
On Fri, May 29, 2009 at 3:14 PM, Daniel Mahler <dmahler@gmail.com> wrote:
Alex,
Thanks, but that is not quite what I need.
The @BeanProperty annotation adds getter/setter methods
with JavaBeans compliant names.
That makes them bean properties, but not fields.
The Java code I am calling does not use the beans interface,
it just calls getFields on the class and looks in the result for what it wants,
but Scala classes do not have public fields (from Java's point of view).
I suspect that there is no way to get Scala objects to have public java fields,
but I would love to be wrong.
Daniel
On 5/29/09, Alex Boisvert <boisvert@intalio.com> wrote:
> This may help,
> http://scala.sygneca.com/code/defining-bean-properties
>
> On Fri, May 29, 2009 at 9:36 AM, Daniel Mahler <dmahler@gmail.com> wrote:
>
>> I am trying to pass a Scala object to some Java code,
>> that calls getFields on the objects class,
>> and it expects to find certain fields there.
>> Scala normally compiles fields into a private Java field,
>> with a getter/setter methods.
>> Is there any way to get fields of a Scala object to be visible
>> as fields in via Reflection?
>>
>> thanks
>> Daniel
>>
>
Mon, 2009-06-01, 20:37
#4
Re: reflection on fields
No it is not for javaspaces, it is an in house framework.
An annotation smells right to me?
On 6/1/09, Nils Kilden-Pedersen wrote:
> I'm guessing this could be for Javaspace Entry objects, which must contain
> public fields. If not, that's another example of the need for public fields
> if full Java framework compatibility is a goal. I can smell another
> annotation.
>
> On Fri, May 29, 2009 at 3:14 PM, Daniel Mahler wrote:
>
>> Alex,
>>
>> Thanks, but that is not quite what I need.
>> The @BeanProperty annotation adds getter/setter methods
>> with JavaBeans compliant names.
>> That makes them bean properties, but not fields.
>> The Java code I am calling does not use the beans interface,
>> it just calls getFields on the class and looks in the result for what it
>> wants,
>> but Scala classes do not have public fields (from Java's point of view).
>> I suspect that there is no way to get Scala objects to have public java
>> fields,
>> but I would love to be wrong.
>>
>> Daniel
>>
>> On 5/29/09, Alex Boisvert wrote:
>> > This may help,
>> > http://scala.sygneca.com/code/defining-bean-properties
>> >
>> > On Fri, May 29, 2009 at 9:36 AM, Daniel Mahler
>> wrote:
>> >
>> >> I am trying to pass a Scala object to some Java code,
>> >> that calls getFields on the objects class,
>> >> and it expects to find certain fields there.
>> >> Scala normally compiles fields into a private Java field,
>> >> with a getter/setter methods.
>> >> Is there any way to get fields of a Scala object to be visible
>> >> as fields in via Reflection?
>> >>
>> >> thanks
>> >> Daniel
>> >>
>> >
>>
>
http://scala.sygneca.com/code/defining-bean-properties
On Fri, May 29, 2009 at 9:36 AM, Daniel Mahler <dmahler@gmail.com> wrote: