0
I am a Java developer studying C# and came across the following difference between the two languages:
https://nerdparadise.com/programming/csharpforjavadevs
Generics
Generics are Much Less fiddly in C#. Partially because they are Both a Compile-time and run-time Concept. There is no Diamond syntax (e.g. new Arraylist<>();) in C# which may sound horrific, but it’s really not that bad. As a bonus, Primitives are Valid types for Generics. So you can have a List Instead of an Awkward List that Suddenly implies nullability.
Invoking methods that require Generics as Parameters are done between the method name and the parenthesis as opposed to between the dot and the method name. Basically constructors and methods in C# use the same Convention whereas Java used Different syntax for Generics for the constructor and methods.
I did not understand the last paragraph. What does it refer to? Following is translation attempt:
Invoking generic methods as parameters is done between the method name and parentheses, as opposed to between the point and the method name. Basically constructors and methods in C# use the same convention while Java used different syntax for generic constructors and methods.
That? https://answall.com/q/10032/101 and https://answall.com/q/150181/101?
– Maniero
In fact the title is poorly formulated, the doubt refers to information present in a specific paragraph, but I do not know if I can answer in a few words. I’ll compare it to the other questions.
– Piovezan
The paragraph says that in C# you call a generic method like this
MeuMetodo<int, string, char>(a, b, c, d)
– Jéf Bueno
@LINQ Got it! Thanks!
– Piovezan
@Piovezan I was writing an answer, but I can’t remember what it’s like in Java
– Jéf Bueno
@LINQ
meuMetodo(<List> lista, <Map> mapa) { ... }
– Piovezan
declares the separate types of arguments?
– user28595
Wow, I traveled in mayonnaise.
meuMetodo(T1 lista, Map<T1> mapa)
... I think you’re right now... and declare the parametric typeT1
next to the class namepublic class MinhaClasse<T1> { ...
– Piovezan