开发者

General Interface Syntax : using variable names

开发者 https://www.devze.com 2023-03-29 06:58 出处:网络
In languages like Java and c#, when you declare an interface the parameters on the functions have variable names. Could you make it more minimal and have the syntax work like this:

In languages like Java and c#, when you declare an interface the parameters on the functions have variable names. Could you make it more minimal and have the syntax work like this:

void Print( String );

Instead of the current

void Print( String str );

Other then readability, where the vari开发者_开发百科ables help define what the parameters are supposed to be, are there reasons require variable names on interfaces?

Readability example:

void doSomething( long, long );

versus

void doSomething( long id, long timeLimitMilli );


Based on my test I would say the answer is "not a bit":

./a/Foo.java

public interface Foo {
    void run(int x);
}

./b/Foo.java

public interface Foo {
    void run(int y);
}

Then

$ sha1sum ./a/Foo.class
7ae75c91f553e09e5a06d5630134e63d650d734e  ./a/Foo.class
$ sha1sum ./b/Foo.class
7ae75c91f553e09e5a06d5630134e63d650d734e  ./b/Foo.class

ie Java cares so little about the parameter names they are discarded entirely on compiling. They are, for all intents and purposes, comments.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号