Skip to content

const/final lists in Java, JavaScript and TypeScript #232

@mittelmark

Description

@mittelmark

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions