bineanzhou / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

@Named shortcut could use parameter's name #257

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
We could use ParaNamer to provide a simple shorthand for the named
annotation. For example, we could reduce boilerplate in this class from this:
  class Foo {
    @Inject @Named("a") String a;
    @Inject @Named("b") String b;

    @Inject
    Foo(@Named("c") String c, @Named("d") String d) {}
  }

to this:
  class Foo {
    @Inject @Named String a;
    @Inject @Named String b;

    @Inject
    Foo(@Named String c, @Named String d) {}
  }

Admittedly, the savings is marginal.
http://paranamer.codehaus.org/

Original issue reported on code.google.com by limpbizkit on 6 Oct 2008 at 10:58

GoogleCodeExporter commented 9 years ago
I've argued against this in the past. The parameter to @Named is public and 
shared,
while we don't expect the same of our method parameter names. Someone can 
innocently
rename a parameter and unknowingly change the behavior of their application. We 
also
shouldn't encourage use of @Named and this would certainly do that by making 
@Named
w/ implicit names easier to use than more type-safe and straightforward 
approaches.

Closing this for now. Re-open if you feel strongly about it.

Original comment by crazybob...@gmail.com on 6 Oct 2008 at 11:33

GoogleCodeExporter commented 9 years ago
Please also consider method and constructor parameter names are not accessible 
at
runtime. The names will be purged from the .class files, if the .java files are 
not
compiled with debug flag set. Even we could use this debug information in .class
files using asm, this does not sound like a good solution to me. If the files 
are not
compiled with debug flag (e.g. for use in a productional environment), we would 
get
an absolute different application behaviour.

Original comment by sven.lin...@gmail.com on 7 Oct 2008 at 3:19