the post name basically says it , im using a function when I require to return a specific object from a list so that I can modify .
private Object myobject;
public void bind(Object obj){
myobject = obj;
}
public Object obtain(){
return myobject;//when this is returned is it myobject ie a c++ reference style object or a copy
}
In the same manner Java’s methods receive arguments by value, it also returns 1 as value.
Keyword return sends following evaluated expression back to its callee. :
For example in return myobject; it evaluates myobject instance variable, which results in the reference value stored in it.
So it’s the reference value stored in myobject which ends up being returned in that statement.
Ugh , by reference I literally mean the c++ & reference where you are able to create int &a = b; editing a would modify b. When I ran the little bit of code on this it didnt edit the original , I Want to know is there anyway that I can edit the original variable with another variable in the same way that c++ does it or should I just build setting methods.
Excellent articles KevinWorkman! Now I don’t have to explain this confusing but important concept by myself anymore! ;D
However I’ve found out some glitches on 'em: :-X
[quote](-2 to the 7th) through (2 to the 7th) -1. Why that little -1 on the end? Because zero is in there, and zero counts as negative.
[/quote]
Value 0 counts as positive in computation. After all, its sign bit is 0 too! :
[quote]boolean - … you’re not supposed to ask. It holds a value of true or false, but it’s really stored as a numeric value, probably in a byte-sized cup.
[/quote]
AFAIK, in Oracle, OpenJDK, Dalvik Java implementations, boolean primitive type is a whole 8-bit byte. 7 bits go to waste! :’(
[quote]… remember that the object is created out on the garbage-collectible heap. Always.
[/quote]
That’s gonna surprise many Java veterans but, since Java 6, it features an über feature called “Escape Analysis”:
Java can decide to allocate a whole object in the stack instead of regular heap if it’s sure its reference won’t escape/survive its local scope boundary! :point:
Java creators, by purpose, have left any explicit address & indirection operators outta it! :o
We’ve only got the member reference operator, which is a simple dot!
And therefore, we can’t use a variable/field to directly change the value stored in another variable/field, ever! :-X
So if you want to have lots of booleans but not waste memory, use a BitSet.
[quote]if it’s sure its reference won’t escape/survive its local scope boundary!
[/quote]
Note that this is more involved than one might expect, and in my experience happens infrequently.