News for hackers. Stuff that matters.
Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @02:43AM (#16527499)
2 main things:

- Boxing/unboxing would not be an issue anymore, so you gain performance.

- Runtime types are enforced: List myList = new List<String>(); myList.add(new Object());

In JAVA, this is ok. In c#, it throws.

Re:How generics were added to .NET by eterm on Tuesday March 06, 2018 @05:26AM (#16528002)
Testing this, it doesn't throw in C#, it just doesn't compile because you can't declare a variable to be a List without declaring the type with it. If you specify myList as List<String> then it still doesn't compile.
Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @09:31AM (#16529047)
For c#, try compiling with IList instead of list.

IList myList = new List<String>(); myList.add(new Object());

Re:How generics were added to .NET by Sharlin on Tuesday March 06, 2018 @10:39AM (#16529459)
To be fair, raw types like List are really deprecated and only exist in order to interface with legacy APIs.
Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @12:04PM (#16530112)
Java? In a lot of cases you still need them. Anything that touches reflections is in that category, plenty of di/ioc systems, or mappers, etc relies on them.
Re:How generics were added to .NET by TheCoelacanth on Tuesday March 06, 2018 @12:17PM (#16530208)
Can you give an example?

Most of the time when reflection is needed I see something like this instead of just a plain list type.

    <T> void foo(List<T> list, Class<? extends T> type) { ... }
Re:How generics were added to .NET by ygra on Tuesday March 06, 2018 @02:57AM (#16527551)
You'd have to call the Java variant via reflection to show the difference at runtime, as the compiler would already enforce that myList.add(new Object()) won't compile. The point stands, though.
Re:How generics were added to .NET by tehlike on Tuesday March 06, 2018 @03:00AM (#16527562)
Reflection is not required. I actually had the code, somehow got deleted

List myList = new ArrayList<String>(); myList.add(new Object());

this would compile.

Re:How generics were added to .NET by ygra on Tuesday March 06, 2018 @03:34AM (#16527654)
Ah, I missed the missing generics on the declaration. Sorry.
Re:How generics were added to .NET by tybit on Tuesday March 06, 2018 @03:59AM (#16527725)
I would say java and c# have both failed on your second point, separate to their respective VMs issues.

It would be nice if mistakes like that were deprecated then eventually fixed, even if over many years/versions.