Optionnal and Named parameters, "Java-style"

See discussion on the coin-dev Archives : PROPOSAL: Named and Optional parameters, "Java-style"

Source code

Exemple

Method declaration

This code :


	public void exemple02({int foo=30, String bar="hi"}) {
		System.out.printf("exemple02(foo=%d, bar=%s)%n", foo, bar);
	}

Will be "converted to" :

	@OptArgsInfo(value={
		@OptArg(name="foo", type=int.class, optional=true),
		@OptArg(name="bar", type=String.class, optional=true),
	})
	public void exemple02(OptArgs $generated$) {
		final int foo = $generated$.retrieve("foo", int.class, 30);
		final String bar = $generated$.retrieve("bar", String.class, "hi");
		
		System.out.printf("exemple02(foo=%d, bar=%s)%n", foo, bar);
	}

Method invocation

This code :

		exemple02(foo:10, bar:"hello");
		exemple02(foo:10);
		exemple02(bar:"hello");
		exemple02();

Will be "converted to" :

		exemple02(OptArgs.make("foo", 10, "bar", "hello"));
		exemple02(OptArgs.make("foo", 10));
		exemple02(OptArgs.make("bar", "hello"));
		exemple02(OptArgs.empty());