So we are clear: you use a value type instead of a reference type when you want to use a reference type. For consistency.
Lolwut?
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
So we are clear: you use a value type instead of a reference type when you want to use a reference type. For consistency.
Lolwut?
I never realized how horrific JNI bindings were until I actually had to do something with it. No wonder my co-workers that previously had to work on JNI bindings kept complaining about it.
Compare to P/Invoke... Wow
6 hours ago, Bass wrote
So we are clear: you use a value type instead of a reference type when you want to use a reference type. For consistency.
Lolwut?
.............. ok, debate ref parameter to C++ and C# creators. I did not create ref parametr, they did.
FYI, I do not want to use ref type, like I said, ref type is not feasible in BioInformatics. I want to use value type and ref parameter. Please don't change my intention. And while I didn't make it so obviouse, ref parameter can skip a lot of unnecessary instuctions and when doing instructions at billion scale, it matters a lot.
So basically you want to pass a pointer to a value type right? But, with that value type either as "read only"/const where you can't change the original value?
I want to pass the actual memory location to the value, which is what ref parameter does right? There is no second level pointer in value type.
This is getting confusing. My thought on int is.
Memory Address -> value.
And a custome class is
Obj Pointer -> realy memory address -> value.
And I want the first one, not second one. "Integer" is first or second?
The C# code:
public static void modify(ref int i)
{
i = 10;
}does not do the same thing as the Java code:
public static void modify(Integer i)
{
i = 10;
}The Java code will only change the value of i inside the method. Which in the case I've contrived does absolutely nothing.
?? I think Integer is fine? It is essentially
public class Interger
{
int _value;
override operator = .....
}
But, still, Integer is not int. It cost extra pointer in memory. Unless I am wrong? Which no one has yet to explain how Integer is structured.
IMO, Integer[ one billion ] = ( 64bits pointer + 32bits value ) * one billion. Which is absolutly big no no in my previous examples.
And just for me only, I totally don't like to use objects when I can use primitives. Some people can debate this to death, but, I want to use int, that's all that matters.
I thought Java couldn't auto box/unbox, then again I haven't used it in ages.
1 hour ago, magicalclick wrote
?? I think Integer is fine? It is essentially
public class Interger
{
int _value;
override operator = .....
}
But, still, Integer is not int. It cost extra pointer in memory. Unless I am wrong? Which no one has yet to explain how Integer is structured.
IMO, Integer[ one billion ] = ( 64bits pointer + 32bits value ) * one billion. Which is absolutly big no no in my previous examples.
And just for me only, I totally don't like to use objects when I can use primitives. Some people can debate this to death, but, I want to use int, that's all that matters.
Java doesn't do operator overloading, so:
public static void doStuff(Integer i) {
i = 5;
}is equivalent to:
public static void doStuff(Integer i) {
i = new Integer(5);
}You're only changing doStuff's reference to i, not changing its actual value (the caller won't see the change). You actually can't do the latter; Integer is immutable in Java.
[edit] And now I remember why I stopped posting. Why in the world does this piece of crap forum dump you back to the first page of a thread when you post?
LOLz, one more reason to hate Java. That means Interger has to be totally used as obj.SetValue(crapValue). And looks like no one said Integer is not an Object, so it is truely stupid to have 64bits pointer + 32bits value in an array of one billion as I have been saying all along.
Yupe, C9 forum is still really bad. But, it doesn't do stuff like, reply and back to first page with no textbox. That was horrifying.
@magicalclick: Basically your first point was entirely correct. Java completely lacks the ability to pass a reference to a value or references, it can only pass references to objects.
Nowhere in Java can you pass a parameter, assign it and have that assignment be anything but local to the method.
You can't in C# either (without the ref or out keywords) because even though it supports operator overloading, to prevent exactly this problem, it does not allow you to override the assignment operator.
C++ is a different kettle of fish because it makes it much more explicit what is a reference or pointer and what is not.
Thanks to clear that up on my first point. Because for some odd reason a guy told me to use some crappy non-value type and pretent it is the same. That actually confused me to think "Integer" is some kind of wacky special value type which apprently is not.
Thanks for the override info too.
For a really thorough and detailed comparison of Java vs C#, see this. It is amazing how primitive Java is compared to C# when you look at the details. Java doesn't even support closures.
Although Java doesn't support REF or OUT keywords, you can still manage it if you sit and think about it for a second or two:
void MyPassByRef(int[] i)
{
i[0] = 42;
}
int Main()
{
int value = 7;
int[] byRef = new int[1]; byRef[0] = value;
MyPassByRef(byRef);
value = byRef[0];
// value is now 42
return value;
}
It supports anonymous classes, which work very similar to closures.
16 minutes ago,Bass wrote
It supports anonymous classes, which work very similar to closures.
It's not very similar at all. For one, anonymous classes do not capture variables/parameters, which is one thing that makes closures so useful.
2 minutes ago,BitFlipper wrote
*snip*
It's not very similar at all. For one, anonymous classes do not capture variables/parameters, which is one thing that makes closures so useful.
They capture any variables marked final.
@Bass:
Yes and final variables cannot be changed, once again losing a lot of what real closures give you.
Plus the syntax compared to C#'s closures are verbose and clunky. Java's anonymous classes are a poor man's closure.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.