Coffeehouse Thread

41 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Java value types Vs .NET

Back to Forum: Coffeehouse
  • User profile image
    Bass

    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? Expressionless

  • User profile image
    BitFlipper

    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 Perplexed

  • User profile image
    magicalclick

    , 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? Expressionless

    .............. 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.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    blowdart

    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?

  • User profile image
    magicalclick

    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?

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    Cupiditas

    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.

  • User profile image
    magicalclick

    ?? 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.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    Cream​Filling512

    I thought Java couldn't auto box/unbox, then again I haven't used it in ages.

  • User profile image
    Cannot​Resolve​Symbol

    , 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?

  • User profile image
    magicalclick

    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.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    Cupiditas

    @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.

  • User profile image
    magicalclick

    @Cupiditas:

    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.

    Leaving WM on 5/2018 if no apps, no dedicated billboards where I drive, no Store name.
    Last modified
  • User profile image
    BitFlipper

    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.

  • User profile image
    evildictait​or

    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; 

  • User profile image
    Bass

    @BitFlipper:

    It supports anonymous classes, which work very similar to closures.

  • User profile image
    BitFlipper

    ,Bass wrote

    @BitFlipper:

    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.

  • User profile image
    Bass

    ,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.

  • User profile image
    BitFlipper

    @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.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.