Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #22231
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2013-02-08 17:16 -0800 |
| References | (3 earlier) <511595c5$0$283$14726298@news.sunsite.dk> <nZgRs.218654$pV4.191473@newsfe21.iad> <51159db8$0$288$14726298@news.sunsite.dk> <de60670c-5ed6-4bae-a79a-dea67e075129@googlegroups.com> <5115a1bb$0$288$14726298@news.sunsite.dk> |
| Message-ID | <c0d2e3c5-2af1-47a5-bbc0-64b1bf1d6d13@googlegroups.com> (permalink) |
| Subject | Re: PUT DATA |
| From | Lew <lewbloch@gmail.com> |
Arne Vajhøj wrote:
> Lew wrote:
>> Arne Vajh�j wrote:
>>> Maybe I am the only one in the known universe that don't know.
>
>>> But let us say we have:
>
>>> X a = new X(aa);
>>> X b = new X(bb);
>>> test(a,b);
>>> void test(X a,X b) {
>>> }
>>> How should the annotation look like, how should it be put on and
>>> how do I get it in test?
>
>> I don't understand your question "How do I get it in test?"
>
> How do I inside the test method retrieve the different
> annotations on a an b?
>>> I know how to put an annotation on the type X that I can get in
>>> test. But that is the same for both a and b. Roedy needs a
>>> different annotation (value).
>>>
>>> I don't think I have ever seen that done with instances.
>
>> Take a look at JPA:
>
>> @Column(name="SURNAME")
>> private String lastName;
>>
>> @Column(name="GIVENNAME")
>> private String firstName;
>>
>> Is that not annotating a field? And annotations can annotate a local variable, too.
>>
>> It's not annotating 'String'.
>>
>> Is that not what you wanted?
>
> Not unless one can call a method with firstName and lastName and
> inside that method retrieve the two column names.
You retrieve annotations via reflection, but that is neither relevant to what I was answering
nor something you normally want to do.
I was answering your assertions that annotations only apply to a type. That's just wrong.
Clearly you can annotate fields, local variables, constructors, methods, ...
Annotations are METAprogramming. They're handled outside the code that is annotated. By other code.
You don't retrieve the annotations inside the method. You get other behavior, like automagically
having a connection to the correct table element. SO THAT YOU DON'T HAVE TO RETRIEVE IT.
That's the whole point of having the annotation. If you want to retrieve the value, don't use annotations.
Or with @NonNull you might get compiler-time explosion over a possibility that the variable could be
null, or a runtime error if it is without having to explicitly code for it. Again, the point is you do the
annotation so the code inside the method doesn't have to deal with it.
Use annotations correctly and your question vanishes. Your assertion that annotations only apply to
types is already wrong.
--
Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
PUT DATA Roedy Green <see_website@mindprod.com.invalid> - 2013-02-08 14:21 -0800
Re: PUT DATA Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 17:34 -0500
Re: PUT DATA Lew <lewbloch@gmail.com> - 2013-02-08 16:13 -0800
Re: PUT DATA Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 19:18 -0500
Re: PUT DATA Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-08 20:44 -0400
Re: PUT DATA Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 19:52 -0500
Re: PUT DATA Lew <lewbloch@gmail.com> - 2013-02-08 17:06 -0800
Re: PUT DATA Lew <lewbloch@gmail.com> - 2013-02-08 17:08 -0800
Re: PUT DATA Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 20:09 -0500
Re: PUT DATA Lew <lewbloch@gmail.com> - 2013-02-08 17:16 -0800
Re: PUT DATA Arne Vajhøj <arne@vajhoej.dk> - 2013-02-08 20:36 -0500
Re: PUT DATA Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-02-09 08:14 -0400
Re: PUT DATA Lew <lewbloch@gmail.com> - 2013-02-08 16:10 -0800
Re: PUT DATA Roedy Green <see_website@mindprod.com.invalid> - 2013-02-09 09:54 -0800
Re: PUT DATA Roedy Green <see_website@mindprod.com.invalid> - 2013-02-09 15:49 -0800
Re: PUT DATA Arne Vajhøj <arne@vajhoej.dk> - 2013-02-09 19:21 -0500
csiph-web