Quote (Klexmoo @ Mar 9 2016 07:32am)
I don't see any issue?
C# generics are a part of the language all the way through the CLR, and generics in Java are (afaik) compiled to typecasts and are not "real" generics.
You can use simple type notation in C# (can use string in lower case and Boolean -> bool in C#, not that it matters though)
*edit:
I ran the program in Java and the output is different so I guess I was wrong.
I think it has something to do with how abstract classes work in Java vs C# but I'm not entirely sure, as I don't code in Java.
Each instantiation you do (in your C# example) of BagOfStrings and BagOfBooleans calls the individual constructors.
The reason I think that they aren't the same value when printing to the console, is that you print the value of the integer for each individual instance, even though it's a static variable.
Abstract classes in C# aren't meant to be instantiated, so I think (I'm not 100% on this) that you simply have the static variable as a member of each BagOfStrings and BagOfBooleans, rather than them sharing the same static variable from their parent class, because the abstract class is never instantiated.
I know exactly what is happening. I knew before I posted the question. You must be new. What I did is called "being an asshole." When some random shows up claiming they want to "help" with programming assignments because they "know" a language it screams "I am a first year university student and I want some extra fg so I will do your homework for you." So, I responded.
But just so we are clear, in C# static members are shared across all instances of the same closed constructed type. This means in my example, I have 2 closed constructed types of the generic type Bag<>. This means each variant, Bag<string> and Bag<bool> will have their own copy of the static member Capacity. This is different from Java, which uses Type Erasure. Java ditches the types at runtime, so thereis no way to specify which type it is, so it gets one copy for the generic. I demonstrated this in my example. The reason I asked this question is because it demonstrates a deeper understanding of both languages. If you are going to offer your services as a tutor to those coming to this forum then you should know a little bit more about the language than just how to write a for-loop. It's annoying.
This post was edited by Minkomonster on Mar 9 2016 11:12pm