You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Michael Giannakopoulos <mi...@gmail.com> on 2011/01/03 18:45:40 UTC

Pointers

Hello to all Apache Commons Developers!
I wish a happy new year and i hope that all your expectations will come
true! I would like to propose a new feature in apache commons... Wouldn't it
be great if commons api provided a pointer operator (like ref in C#) so as
to pass arguments in functions by references (only for primitive types...)
and these arguments to change values... I would like to hear your thoughts
on this! Thanks for your time!

Re: Pointers

Posted by "Stephen J. Butler" <st...@gmail.com>.
2011/1/3 Stephen J. Butler <st...@gmail.com>:
> public function foo( ref int a ) { a = 42; }
> public function bar() {
>  int b = 0;
>
>  foo( ref b );
>
>  // b == 42
> }

And excuse my rather bad C# code which doesn't compile... been
spending way too much time in scripting languages lately.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Rafał Krupiński <r....@gmail.com>.
W dniu 03.01.2011 20:15, Stephen J. Butler pisze:
> 2011/1/3 Rafał Krupiński<r....@gmail.com>:
>> W dniu 03.01.2011 18:45, Michael Giannakopoulos pisze:
>>>
>>> Hello to all Apache Commons Developers!
>>> I wish a happy new year and i hope that all your expectations will come
>>> true! I would like to propose a new feature in apache commons... Wouldn't
>>> it
>>> be great if commons api provided a pointer operator (like ref in C#) so as
>>> to pass arguments in functions by references (only for primitive types...)
>>> and these arguments to change values... I would like to hear your thoughts
>>> on this! Thanks for your time!
>>>
>>
>> Do you mean something like
>> class IntRef{
>> private int value;
>> public int getValue()...
>> public void setValue(int)...
>> }
>>
>> ?
>
> He mentions "ref" in C#, which works something like this:
>
> public function foo( ref int a ) { a = 42; }
> public function bar() {
>    int b = 0;
>
>    foo( ref b );
>
>    // b == 42
> }
>
> I don't see how Commons could accomplish this goal.

Well, obviously you can't introduce operators with libraries, after all 
java ain't perl ;-)

The simplest way to achieve anything resembling output parameters are 
mutable flavor of java.lang.Integer &co classes.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by "Stephen J. Butler" <st...@gmail.com>.
2011/1/3 Rafał Krupiński <r....@gmail.com>:
> W dniu 03.01.2011 18:45, Michael Giannakopoulos pisze:
>>
>> Hello to all Apache Commons Developers!
>> I wish a happy new year and i hope that all your expectations will come
>> true! I would like to propose a new feature in apache commons... Wouldn't
>> it
>> be great if commons api provided a pointer operator (like ref in C#) so as
>> to pass arguments in functions by references (only for primitive types...)
>> and these arguments to change values... I would like to hear your thoughts
>> on this! Thanks for your time!
>>
>
> Do you mean something like
> class IntRef{
> private int value;
> public int getValue()...
> public void setValue(int)...
> }
>
> ?

He mentions "ref" in C#, which works something like this:

public function foo( ref int a ) { a = 42; }
public function bar() {
  int b = 0;

  foo( ref b );

  // b == 42
}

I don't see how Commons could accomplish this goal.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Rafał Krupiński <r....@gmail.com>.
W dniu 03.01.2011 18:45, Michael Giannakopoulos pisze:
> Hello to all Apache Commons Developers!
> I wish a happy new year and i hope that all your expectations will come
> true! I would like to propose a new feature in apache commons... Wouldn't it
> be great if commons api provided a pointer operator (like ref in C#) so as
> to pass arguments in functions by references (only for primitive types...)
> and these arguments to change values... I would like to hear your thoughts
> on this! Thanks for your time!
>

Do you mean something like
class IntRef{
private int value;
public int getValue()...
public void setValue(int)...
}

?

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Michael Giannakopoulos <mi...@gmail.com>.
Thank you all guys! You 're amazing!

Re: Pointers

Posted by Stephen Williams <sc...@gmail.com>.
Hah, just sent a reply stating just that.  Thanks.

Stephen

On Fri, Jan 28, 2011 at 2:45 PM, Brent Worden <br...@gmail.com>wrote:

> Actually, funkyChanger will not work because you are effectively
> reassigning the argument.  Since all arguments in Java are passed by
> value, the assignment is not realized by the caller.
>
> The only ways to get argument changes surfaced to the caller are using
> a typed return or passing in an argument whose state can be modified
> (and not by assignment).
>
> As discussed in this thread, one way to accomplish this for primitives
> is by using the MutableXxxx types found in Apache Commons Lang.
> Another common way is to using a single element array.
>
> Thanks,
>
> Brent.
>

Re: Pointers

Posted by Brent Worden <br...@gmail.com>.
Actually, funkyChanger will not work because you are effectively
reassigning the argument.  Since all arguments in Java are passed by
value, the assignment is not realized by the caller.

The only ways to get argument changes surfaced to the caller are using
a typed return or passing in an argument whose state can be modified
(and not by assignment).

As discussed in this thread, one way to accomplish this for primitives
is by using the MutableXxxx types found in Apache Commons Lang.
Another common way is to using a single element array.

Thanks,

Brent.

On Fri, Jan 28, 2011 at 4:01 PM, Stephen Williams <sc...@gmail.com> wrote:
> All objects are passed as references in Java.
> All fundamental scalar types have Object wrapped versions.
> An argument that is meant to be modified just needs to be an object
> reference.
>
> So, you can simply go from:
> void funkyReader(int arg) { arg++; }
> to:
> void funkyChanger(Integer arg) { arg++; }
>
> If it needs to be threadsafe, simply synchronize on the object everywhere it
> is used.
>
> Autoboxing will not cause an 'int' variable to change as it is just copied
> to create the temporary object.
>
> Stephen
>
> On Tue, Jan 4, 2011 at 12:58 AM, Julien Aymé <ju...@gmail.com> wrote:
>
>> If you only use boolean, integer and long, you can also use AtomicXXX
>> from java.util.concurrent.atomic (if you have to use them in a
>> multi-threaded environment).
>> Otherwise, the MutableXXX wrappers in Commons Lang are good.
>>
>> Julien
>>
>> 2011/1/3 Paul Benedict <pb...@apache.org>:
>> > Michael,
>> >
>> > Primitives are passed by value in Java. If you want to "modify"
>> primitives,
>> > use the MutableXXX wrappers in Commons Lang.
>> >
>> > Paul
>> >
>> > On Mon, Jan 3, 2011 at 3:01 PM, Michael Giannakopoulos <
>> miccagiann@gmail.com
>> >> wrote:
>> >
>> >> I mean exactly the same thing as C# but from the replies i see that's a
>> >> difficult task and also that has little to do with apache commons...
>> >> Because
>> >> i use java a lot it's annoying the fact that specific variables that i
>> want
>> >> to change values in other functions cannot be passed as arguments but
>> >> instead you have to declare them as arrays or other objects... Thanks
>> for
>> >> all the replies. Do you believe that something like that can start in
>> >> commons?
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
>
> --
> --
> Stephen D. Williams sdw@lig.net scienteer@gmail.com LinkedIn:
> http://sdw.st/in
> V:650-450-UNIX (8649) V:866.SDW.UNIX V:703.371.9362 F:703.995.0407
> AIM:sdw Skype:StephenDWilliams Resume: http://sdw.st/gres
> Personal: sdw.st facebook.com/sdwlig twitter.com/scienteer
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Matt Benson <gu...@gmail.com>.
Adding fuel to the fire, note that [lang] 3.0 will include the Pair<L, R> class.

Matt

On 1/28/11, Stephen Williams <sd...@lig.net> wrote:
> On 1/28/11 3:14 PM, James Ring wrote:
>> Hey,
>>
>> On Fri, Jan 28, 2011 at 3:00 PM, Stephen Williams<sc...@gmail.com>
>> wrote:
>>> True, you shouldn't synchronize on any object that A) you want to change
>>> and
>>> B) can only be changed by being replaced by a newly constructed object.
>>> If
>>> Integer, for instance, had a setter method, then it could still have been
>>> used in this way.  However, it seems to be immutable.  I generally just
>>> create something like the following to synchronize:
>> Just because an object is immutable doesn't mean that you shouldn't
>> necessarily synchronize on it.
> The point of the suggested link, which is valid, is to make sure you aren't
> synchronizing on a variable when you are going to
> replace the value of that variable by assignment.  Since you are really
> synchronizing on what the object variable is referencing,
> assigning to it later means that the objects involved before and after
> assignment are different objects.  Therefore, the
> synchronization is completely broken.
>>> Object lockArg;
>> For example, Object lockArg = new Object() is immutable but is fine
>> for synchronization.
>>
>> FYI java.util.concurrent has a much better suite of synchronization
>> utilities than the language primitives provide.
>
> Absolutely, very cool features.  But not always needed.
>>> ...
>>>
>>> About returning tuples:
>>> Returning more than one value from a method has two reasonable solutions
>>> that seem minimal for their use cases: returning a tuple as a single
>>> value
>>> or making one or more calls to a callback method.  The simplest case is
>>> when
>>> multiple values need to be returned.  While callbacks have their place
>>> when
>>> you need to trigger more operations incrementally, they are cumbersome as
>>> you need to define a class and provide an implementation, although the
>>> latter can be an anonymous implementation.  Many have complained about
>>> the
>>> lack in Java of pair<>, however with the object reference system, it is
>>> easy
>>> to do this with arrays.  If the types are all the same, like String[],
>>> this
>>> is completely typesafe.  Otherwise, you can use Object[].  You can also
>>> define a return type class to fill, however that is cumbersome.  In
>>> addition
>>> to Object[], a TreeMap can be a good solution, especially when more than
>>> a
>>> few parameters are needed and they might change over time.
>> Returning tuples indicates that you are missing some sort of
>> abstraction that should be introduced to represent the thing you are
>> returning. Defining a class and providing an implementation is way
>> less cumbersome than dealing with the bugs that crop up when you fail
>> to properly encapsulate your state. Returning a TreeMap is probably
>> bad for the same reason.
>
> Certainly, that is the common analysis.  And it can be true in many cases.
> However, you could argue your point in the extreme: The
> return value for any method should be a defined type.  Rather than returning
> an int, why not "ScreenWidthType"?  There is a
> balancing need, which most ignore or do not see until it is too late, to be
> concise and not promote "class diarrhea".  That is a
> term I coined after working on a project where the primary development was
> by an offshore team who never met an idea for creating
> new classes that they couldn't apply several times a day.  A single
> transaction through the system involved substantially all of the
> 600 classes that they had created in a few months.
>
> If you must create a return type, do it as an inner class right at the
> definition of the method.  Having many tiny classes with 10
> lines of real code each can become a huge complexity burden: complex
> simplicity does not result in anything like the lowest total
> complexity.  If the types are common and key objects in your system, then a
> separate abstraction is appropriate.  That is seldom
> true of everything in a system.
>
> As for the TreeMap method, both Qt/C++ and Objective-C includes a properties
> system where arbitrary values can be ferried by
> objects.  For certain things, like returning sets that are potentially
> variable such as the results of an XML parse, this is ideal.
>
>>> Stephen
>> Regards,
>> James
> sdw
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Stephen Williams <sd...@lig.net>.
On 1/28/11 3:14 PM, James Ring wrote:
> Hey,
>
> On Fri, Jan 28, 2011 at 3:00 PM, Stephen Williams<sc...@gmail.com>  wrote:
>> True, you shouldn't synchronize on any object that A) you want to change and
>> B) can only be changed by being replaced by a newly constructed object.  If
>> Integer, for instance, had a setter method, then it could still have been
>> used in this way.  However, it seems to be immutable.  I generally just
>> create something like the following to synchronize:
> Just because an object is immutable doesn't mean that you shouldn't
> necessarily synchronize on it.
The point of the suggested link, which is valid, is to make sure you aren't synchronizing on a variable when you are going to 
replace the value of that variable by assignment.  Since you are really synchronizing on what the object variable is referencing, 
assigning to it later means that the objects involved before and after assignment are different objects.  Therefore, the 
synchronization is completely broken.
>> Object lockArg;
> For example, Object lockArg = new Object() is immutable but is fine
> for synchronization.
>
> FYI java.util.concurrent has a much better suite of synchronization
> utilities than the language primitives provide.

Absolutely, very cool features.  But not always needed.
>> ...
>>
>> About returning tuples:
>> Returning more than one value from a method has two reasonable solutions
>> that seem minimal for their use cases: returning a tuple as a single value
>> or making one or more calls to a callback method.  The simplest case is when
>> multiple values need to be returned.  While callbacks have their place when
>> you need to trigger more operations incrementally, they are cumbersome as
>> you need to define a class and provide an implementation, although the
>> latter can be an anonymous implementation.  Many have complained about the
>> lack in Java of pair<>, however with the object reference system, it is easy
>> to do this with arrays.  If the types are all the same, like String[], this
>> is completely typesafe.  Otherwise, you can use Object[].  You can also
>> define a return type class to fill, however that is cumbersome.  In addition
>> to Object[], a TreeMap can be a good solution, especially when more than a
>> few parameters are needed and they might change over time.
> Returning tuples indicates that you are missing some sort of
> abstraction that should be introduced to represent the thing you are
> returning. Defining a class and providing an implementation is way
> less cumbersome than dealing with the bugs that crop up when you fail
> to properly encapsulate your state. Returning a TreeMap is probably
> bad for the same reason.

Certainly, that is the common analysis.  And it can be true in many cases.  However, you could argue your point in the extreme: The 
return value for any method should be a defined type.  Rather than returning an int, why not "ScreenWidthType"?  There is a 
balancing need, which most ignore or do not see until it is too late, to be concise and not promote "class diarrhea".  That is a 
term I coined after working on a project where the primary development was by an offshore team who never met an idea for creating 
new classes that they couldn't apply several times a day.  A single transaction through the system involved substantially all of the 
600 classes that they had created in a few months.

If you must create a return type, do it as an inner class right at the definition of the method.  Having many tiny classes with 10 
lines of real code each can become a huge complexity burden: complex simplicity does not result in anything like the lowest total 
complexity.  If the types are common and key objects in your system, then a separate abstraction is appropriate.  That is seldom 
true of everything in a system.

As for the TreeMap method, both Qt/C++ and Objective-C includes a properties system where arbitrary values can be ferried by 
objects.  For certain things, like returning sets that are potentially variable such as the results of an XML parse, this is ideal.

>> Stephen
> Regards,
> James
sdw


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by James Ring <sj...@jdns.org>.
Hey,

On Fri, Jan 28, 2011 at 3:00 PM, Stephen Williams <sc...@gmail.com> wrote:
> True, you shouldn't synchronize on any object that A) you want to change and
> B) can only be changed by being replaced by a newly constructed object.  If
> Integer, for instance, had a setter method, then it could still have been
> used in this way.  However, it seems to be immutable.  I generally just
> create something like the following to synchronize:

Just because an object is immutable doesn't mean that you shouldn't
necessarily synchronize on it.

> Object lockArg;

For example, Object lockArg = new Object() is immutable but is fine
for synchronization.

FYI java.util.concurrent has a much better suite of synchronization
utilities than the language primitives provide.

> A method I use for returning more than one value would be useful here also:
> Integer[] arg = new Integer[](1);
> arg[0] = new Integer(5);
> // or with autoboxing:
> arg[0] = 5;
>
> void funkyChanger(Integer[] arg) {
>    synchronized (arg) { ...  arg[0]++; ... }
> }
>
> Is there a problem with this as a general idiom?  You could use naming to
> signal the nature as indirect vs. logically an array.  And, a future version
> of Java could use syntactic sugar for 'ref' to do this by autoboxing the 1
> deep array also.
>
> About returning tuples:
> Returning more than one value from a method has two reasonable solutions
> that seem minimal for their use cases: returning a tuple as a single value
> or making one or more calls to a callback method.  The simplest case is when
> multiple values need to be returned.  While callbacks have their place when
> you need to trigger more operations incrementally, they are cumbersome as
> you need to define a class and provide an implementation, although the
> latter can be an anonymous implementation.  Many have complained about the
> lack in Java of pair<>, however with the object reference system, it is easy
> to do this with arrays.  If the types are all the same, like String[], this
> is completely typesafe.  Otherwise, you can use Object[].  You can also
> define a return type class to fill, however that is cumbersome.  In addition
> to Object[], a TreeMap can be a good solution, especially when more than a
> few parameters are needed and they might change over time.

Returning tuples indicates that you are missing some sort of
abstraction that should be introduced to represent the thing you are
returning. Defining a class and providing an implementation is way
less cumbersome than dealing with the bugs that crop up when you fail
to properly encapsulate your state. Returning a TreeMap is probably
bad for the same reason.

> Stephen

Regards,
James

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Stephen Williams <sc...@gmail.com>.
True, you shouldn't synchronize on any object that A) you want to change and
B) can only be changed by being replaced by a newly constructed object.  If
Integer, for instance, had a setter method, then it could still have been
used in this way.  However, it seems to be immutable.  I generally just
create something like the following to synchronize:
Object lockArg;

A method I use for returning more than one value would be useful here also:
Integer[] arg = new Integer[](1);
arg[0] = new Integer(5);
// or with autoboxing:
arg[0] = 5;

void funkyChanger(Integer[] arg) {
    synchronized (arg) { ...  arg[0]++; ... }
}

Is there a problem with this as a general idiom?  You could use naming to
signal the nature as indirect vs. logically an array.  And, a future version
of Java could use syntactic sugar for 'ref' to do this by autoboxing the 1
deep array also.

About returning tuples:
Returning more than one value from a method has two reasonable solutions
that seem minimal for their use cases: returning a tuple as a single value
or making one or more calls to a callback method.  The simplest case is when
multiple values need to be returned.  While callbacks have their place when
you need to trigger more operations incrementally, they are cumbersome as
you need to define a class and provide an implementation, although the
latter can be an anonymous implementation.  Many have complained about the
lack in Java of pair<>, however with the object reference system, it is easy
to do this with arrays.  If the types are all the same, like String[], this
is completely typesafe.  Otherwise, you can use Object[].  You can also
define a return type class to fill, however that is cumbersome.  In addition
to Object[], a TreeMap can be a good solution, especially when more than a
few parameters are needed and they might change over time.

Stephen

On Fri, Jan 28, 2011 at 2:21 PM, James Ring <sj...@jdns.org> wrote:

> Hey,
>
> On Fri, Jan 28, 2011 at 2:01 PM, Stephen Williams <sc...@gmail.com>
> wrote:
> > All objects are passed as references in Java.
> > All fundamental scalar types have Object wrapped versions.
> > An argument that is meant to be modified just needs to be an object
> > reference.
> >
> > So, you can simply go from:
> > void funkyReader(int arg) { arg++; }
> > to:
> > void funkyChanger(Integer arg) { arg++; }
> >
> > If it needs to be threadsafe, simply synchronize on the object everywhere
> it
> > is used.
>
> It's a bad idea to synchronize on the wrapper objects of primitive
> types: http://www.theothertomelliott.com/node/40
>
> This includes Integers.
>
> Regards,
> James
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
-- 
Stephen D. Williams sdw@lig.net scienteer@gmail.com LinkedIn:
http://sdw.st/in
V:650-450-UNIX (8649) V:866.SDW.UNIX V:703.371.9362 F:703.995.0407
AIM:sdw Skype:StephenDWilliams Resume: http://sdw.st/gres
Personal: sdw.st facebook.com/sdwlig twitter.com/scienteer

Re: Pointers

Posted by James Ring <sj...@jdns.org>.
Hey,

On Fri, Jan 28, 2011 at 2:01 PM, Stephen Williams <sc...@gmail.com> wrote:
> All objects are passed as references in Java.
> All fundamental scalar types have Object wrapped versions.
> An argument that is meant to be modified just needs to be an object
> reference.
>
> So, you can simply go from:
> void funkyReader(int arg) { arg++; }
> to:
> void funkyChanger(Integer arg) { arg++; }
>
> If it needs to be threadsafe, simply synchronize on the object everywhere it
> is used.

It's a bad idea to synchronize on the wrapper objects of primitive
types: http://www.theothertomelliott.com/node/40

This includes Integers.

Regards,
James

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Stephen Williams <sc...@gmail.com>.
All objects are passed as references in Java.
All fundamental scalar types have Object wrapped versions.
An argument that is meant to be modified just needs to be an object
reference.

So, you can simply go from:
void funkyReader(int arg) { arg++; }
to:
void funkyChanger(Integer arg) { arg++; }

If it needs to be threadsafe, simply synchronize on the object everywhere it
is used.

Autoboxing will not cause an 'int' variable to change as it is just copied
to create the temporary object.

Stephen

On Tue, Jan 4, 2011 at 12:58 AM, Julien Aymé <ju...@gmail.com> wrote:

> If you only use boolean, integer and long, you can also use AtomicXXX
> from java.util.concurrent.atomic (if you have to use them in a
> multi-threaded environment).
> Otherwise, the MutableXXX wrappers in Commons Lang are good.
>
> Julien
>
> 2011/1/3 Paul Benedict <pb...@apache.org>:
> > Michael,
> >
> > Primitives are passed by value in Java. If you want to "modify"
> primitives,
> > use the MutableXXX wrappers in Commons Lang.
> >
> > Paul
> >
> > On Mon, Jan 3, 2011 at 3:01 PM, Michael Giannakopoulos <
> miccagiann@gmail.com
> >> wrote:
> >
> >> I mean exactly the same thing as C# but from the replies i see that's a
> >> difficult task and also that has little to do with apache commons...
> >> Because
> >> i use java a lot it's annoying the fact that specific variables that i
> want
> >> to change values in other functions cannot be passed as arguments but
> >> instead you have to declare them as arrays or other objects... Thanks
> for
> >> all the replies. Do you believe that something like that can start in
> >> commons?
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>


-- 
-- 
Stephen D. Williams sdw@lig.net scienteer@gmail.com LinkedIn:
http://sdw.st/in
V:650-450-UNIX (8649) V:866.SDW.UNIX V:703.371.9362 F:703.995.0407
AIM:sdw Skype:StephenDWilliams Resume: http://sdw.st/gres
Personal: sdw.st facebook.com/sdwlig twitter.com/scienteer

Re: Pointers

Posted by Julien Aymé <ju...@gmail.com>.
If you only use boolean, integer and long, you can also use AtomicXXX
from java.util.concurrent.atomic (if you have to use them in a
multi-threaded environment).
Otherwise, the MutableXXX wrappers in Commons Lang are good.

Julien

2011/1/3 Paul Benedict <pb...@apache.org>:
> Michael,
>
> Primitives are passed by value in Java. If you want to "modify" primitives,
> use the MutableXXX wrappers in Commons Lang.
>
> Paul
>
> On Mon, Jan 3, 2011 at 3:01 PM, Michael Giannakopoulos <miccagiann@gmail.com
>> wrote:
>
>> I mean exactly the same thing as C# but from the replies i see that's a
>> difficult task and also that has little to do with apache commons...
>> Because
>> i use java a lot it's annoying the fact that specific variables that i want
>> to change values in other functions cannot be passed as arguments but
>> instead you have to declare them as arrays or other objects... Thanks for
>> all the replies. Do you believe that something like that can start in
>> commons?
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Paul Benedict <pb...@apache.org>.
Michael,

Primitives are passed by value in Java. If you want to "modify" primitives,
use the MutableXXX wrappers in Commons Lang.

Paul

On Mon, Jan 3, 2011 at 3:01 PM, Michael Giannakopoulos <miccagiann@gmail.com
> wrote:

> I mean exactly the same thing as C# but from the replies i see that's a
> difficult task and also that has little to do with apache commons...
> Because
> i use java a lot it's annoying the fact that specific variables that i want
> to change values in other functions cannot be passed as arguments but
> instead you have to declare them as arrays or other objects... Thanks for
> all the replies. Do you believe that something like that can start in
> commons?
>

Re: Pointers

Posted by Michael Giannakopoulos <mi...@gmail.com>.
I mean exactly the same thing as C# but from the replies i see that's a
difficult task and also that has little to do with apache commons... Because
i use java a lot it's annoying the fact that specific variables that i want
to change values in other functions cannot be passed as arguments but
instead you have to declare them as arrays or other objects... Thanks for
all the replies. Do you believe that something like that can start in
commons?

Re: Pointers

Posted by Matt Benson <gu...@gmail.com>.
On Jan 3, 2011, at 11:54 AM, Paul Benedict wrote:

> I believe you're looking for JDK 7 method handles:
> http://java.sun.com/developer/technicalArticles/DynTypeLang/
> 

Actually it sounded to me as though he was talking along the lines of Mutable* in [lang].  :/

Matt

> Paul
> 
> On Mon, Jan 3, 2011 at 11:45 AM, Michael Giannakopoulos <
> miccagiann@gmail.com> wrote:
> 
>> Hello to all Apache Commons Developers!
>> I wish a happy new year and i hope that all your expectations will come
>> true! I would like to propose a new feature in apache commons... Wouldn't
>> it
>> be great if commons api provided a pointer operator (like ref in C#) so as
>> to pass arguments in functions by references (only for primitive types...)
>> and these arguments to change values... I would like to hear your thoughts
>> on this! Thanks for your time!
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: Pointers

Posted by Paul Benedict <pb...@apache.org>.
I believe you're looking for JDK 7 method handles:
http://java.sun.com/developer/technicalArticles/DynTypeLang/

Paul

On Mon, Jan 3, 2011 at 11:45 AM, Michael Giannakopoulos <
miccagiann@gmail.com> wrote:

> Hello to all Apache Commons Developers!
> I wish a happy new year and i hope that all your expectations will come
> true! I would like to propose a new feature in apache commons... Wouldn't
> it
> be great if commons api provided a pointer operator (like ref in C#) so as
> to pass arguments in functions by references (only for primitive types...)
> and these arguments to change values... I would like to hear your thoughts
> on this! Thanks for your time!
>