These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Access private persistent properties from static inner class
PostPosted: Wed Apr 18, 2007 8:43 am 
Newbie

Joined: Wed Apr 18, 2007 8:28 am
Posts: 2
Surely someone must have had this problem before....

If you try to access a private persistent property from an inner class, it fails silently, making no change to the database.

Code:
public class Robot {

   // Persistent property
   private int number;
   
   public int getNumber() {return number;}
   
   private void setNumber(int number) {this.number = number;}
   
   
   public static class PerformanceTuner {
      
      // This does nothing!!
      public void tunePerformance(Robot robot) {
         robot.setNumber(robot.getNumber()+3);
      }
      
   }
   
}




I'm guessing this is because you can't override private properties and so when you call setNumber it accesses the original object instead of the EnhancerByCLib.

I'm avoiding this problem by making my setters have package level access instead of private, anyone have any better solutions?
[/code]


Last edited by bigbadwolf on Wed Apr 18, 2007 8:47 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 8:45 am 
Newbie

Joined: Wed Apr 18, 2007 8:28 am
Posts: 2
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.