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

Internal fields names

2 replies
edmondo1984
Joined: 2011-09-14,
User offline. Last seen 28 weeks 3 days ago.
Dear all,
I am trying to inject a private field with reflection, in a test suite. I have discovered that the name of the field has changed compared to the one I have declared.


Namely the following:


  private var active = false;
  @Autowired
  private var gigaSpace: GigaSpace = _;

become:

com$gottex$gottware$datafeeds$mocks$MockRealTimeConnector$$gigaSpace

while active stays the same when I inspect the Fields[] collection.

Why does it happen? Should I not rely anymore on fields name for doing reflection in my tests?

Best Regards

Edmondo
Viktor Klang
Joined: 2008-12-17,
User offline. Last seen 1 year 27 weeks ago.
Re: Internal fields names


On Tue, Jan 3, 2012 at 2:00 PM, Edmondo Porcu <edmondo [dot] porcu [at] gmail [dot] com> wrote:
Dear all,
I am trying to inject a private field with reflection, in a test suite. I have discovered that the name of the field has changed compared to the one I have declared.


Namely the following:


  private var active = false;
  @Autowired
  private var gigaSpace: GigaSpace = _;

become:

com$gottex$gottware$datafeeds$mocks$MockRealTimeConnector$$gigaSpace

while active stays the same when I inspect the Fields[] collection.

Why does it happen? Should I not rely anymore on fields name for doing reflection in my tests?

I'm pretty sure that field names are an implementation detail and aren't guaranteed in the Scala Spec.  

Best Regards

Edmondo



--
Viktor Klang

Akka Tech LeadTypesafe - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang
Joshua.Suereth
Joined: 2008-09-02,
User offline. Last seen 32 weeks 5 days ago.
Re: Internal fields names

Exactly true.  If it's a var you can inject with the "foo_$eq" method.  See the scala-mojo-support project for a working inject example for plexus.

On Jan 3, 2012 8:08 AM, "√iktor Ҡlang" <viktor [dot] klang [at] gmail [dot] com> wrote:


On Tue, Jan 3, 2012 at 2:00 PM, Edmondo Porcu <edmondo [dot] porcu [at] gmail [dot] com> wrote:
Dear all,
I am trying to inject a private field with reflection, in a test suite. I have discovered that the name of the field has changed compared to the one I have declared.


Namely the following:


  private var active = false;
  @Autowired
  private var gigaSpace: GigaSpace = _;

become:

com$gottex$gottware$datafeeds$mocks$MockRealTimeConnector$$gigaSpace

while active stays the same when I inspect the Fields[] collection.

Why does it happen? Should I not rely anymore on fields name for doing reflection in my tests?

I'm pretty sure that field names are an implementation detail and aren't guaranteed in the Scala Spec.  

Best Regards

Edmondo



--
Viktor Klang

Akka Tech LeadTypesafe - Enterprise-Grade Scala from the Experts

Twitter: @viktorklang

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