what I mean is that in C #, for example, I can write a generic method like this:
public static void Concatenate<T> (T arg1, T arg2) { Console.WriteLine(arg1.ToString() + arg2.ToString()); }
and then if I call the method in different ways:
Concatenate("one", "two");
alternately, I could call the method as follows: Concatenate<string>("one", "two"); and be sure that only lines get ...
now if i try the same thing in java
public static <T> void concatenate(T arg1, T arg2) { System.out.println(arg1.toString() + arg2.toString()); }
and call the method exactly the same as in the C # example:
concatenate("one", "two");
As far as I know, I cannot name a method like Concatenate<string>("one", "two"); as this will give me an error
Is there a way to add the type of security I found in C #?
so I donβt risk being able to just put any type anywhere and just get a warning ...
a better example would be to use variable arguments
in C # I would do:
public static void QuickSort<T>(params T[] args)
and by calling it, I am sure that only one of the parameters, for example, does the following:
QuickSort<int>(5, 9, 7, 3, 2, 5, 4, 1);
whereas in java I could do this:
quickSort(5, "nine", 7, 3, "two", 5, 4, 1);
and get nothing but a warning from the IDE, while it will give an error in C #
so my question is: is there a way to βblockβ the parameter type in java, as I can, in C #, a-la QuickSort<int>(args) , and not quickSort(args) ?