fanyapeng / javadude

Automatically exported from code.google.com/p/javadude
0 stars 0 forks source link

Default parameters #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
add annotations like

    public void foo(@Default(10) int x, @Default("hello") String y) 
{...}

public void foo(int x, String y) {...}

that expands in superclass to

public abstract void foo(int x, String y);
public void foo(int x) {foo(x, "hello");}
public void foo(String y) {foo(10, y);}
public void foo() {foo(10, "hello");}

if parameter types are unique enough(by type), can have all permutations. 
if some parameter types are the same, need to define positionally -- 
cannot have

    public void foo(@Default(10) int x, @Default("hello") String y) 
{...}

define

public abstract void foo(int x, int y);
public void foo(int x) {foo(x, 20);}
public void foo(int y) {foo(10, y);}
public void foo() {foo(10, 20);}

won't compile -- need to generate

public abstract void foo(int x, int y);
public void foo() {foo(10, 20);}
public void foo(int x) {foo(x, 20);}

easiest way to implement and describe would be to just say parameters can 
only be dropped from the end, ough:

    public void foo(@Default(10) int x, @Default("hello") String y) 
{...}

would expand in superclass to

public void foo() {foo(10, "hello");}
public void foo(int x) {foo(x, "hello");}
public abstract void foo(int x, String y);

by just adding one parameter at a time

user could always add other overrides for missing permutations...

Original issue reported on code.google.com by scott%ja...@gtempaccount.com on 23 Jul 2008 at 1:59

GoogleCodeExporter commented 9 years ago

Original comment by scott%ja...@gtempaccount.com on 26 Aug 2008 at 2:45

GoogleCodeExporter commented 9 years ago

Original comment by scott%ja...@gtempaccount.com on 26 Aug 2008 at 2:55