Hello,
if I create a List with () - it becomes const/final in Java, JavaScript and Typescript. Here an example:
public static class Test3 {
public static List<int>() GetValues (int x) {
List<int>() y ;
for (int i = 0; i < x; i++) {
y.Add(i);
}
return(y);
}
public static void Run (string[] args)
{
List<int>() x; // declared const in JavaScript/TypeScript and final in Java
List<int>() y; // declared const in JavaScript/TypeScript and final in Java
x.Add(1); // works on C, C++, C#, D, Java, JavaScript, TypeScript, Python
Console.WriteLine($"List x has {x.Count} elements!");
y = GetValues(5); // works: C, C++, C#, D, Python - fail: Java, Javascript and Typescript as y ist final/const
Console.WriteLine($"List y has {y.Count} elements!");
}
public static int Main (string[] args)
{
Test3.Run(args);
return(0);
}
}
Is this the expected behavior? Or should I replace the line with the y-initialization as:
List<int> y = GetValues(5);
Hello,
if I create a List with () - it becomes const/final in Java, JavaScript and Typescript. Here an example:
Is this the expected behavior? Or should I replace the line with the y-initialization as: