File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java pass by value.

 
jing hu
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to assign set. But now it doesn't meet my requirement.
when using set = newSet; it doesn't change.
I know the reason. I want to know if there is a convenient method assign set with newSet.
Thanks.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the Set you pass to the method is not null, you could call set.clear().
But you could also return a Set, instead of passing it as a parameter.
 
jing hu
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah,I can return the newSet directly in this case.
But this is just a example. in the reality, Maybe I can't modify the function return type or there is already an returned type.
So any other method?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not that I can think of. "Clear and Add" or "Create, Add and Return". That looks enough to me.

Maybe I can't modify the function return type or there is already an returned type.

Then you'd probably pass an existing Set, or encapsulate the Set in a object and pass the object to the method.
 
jing hu
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok.
I can write like this.

set.clear();
set.addAll(newSet);

what about the code efficiency ?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic