Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > PUT DATA

Reply
Thread Tools

PUT DATA

 
 
Lew
Guest
Posts: n/a
 
      02-09-2013
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 TORETRIEVE 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
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      02-09-2013
On 2/8/2013 8:16 PM, Lew wrote:
> 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


In this case?

> , 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.


Maybe you should read the context.

I answered a question whether annotations could solve a specific problem.

For annotations to solve that problem they would need to be applied
to instances similar to how it can be done for types.

All the stuff you list are utterly irrelevant for the question asked.

Arne



 
Reply With Quote
 
 
 
 
Arved Sandstrom
Guest
Posts: n/a
 
      02-09-2013
On 02/08/2013 09:36 PM, Arne Vajh°j wrote:
[ SNIP ]

>
> Maybe you should read the context.
>
> I answered a question whether annotations could solve a specific problem.
>
> For annotations to solve that problem they would need to be applied
> to instances similar to how it can be done for types.
>
> All the stuff you list are utterly irrelevant for the question asked.
>
> Arne
>

I think the best bet here is to wait for JDK 8. JEP 118, which appears
to still be in play, is for exactly this.

I just now tried this out with the latest build, and it looks like they
are working on it. You can get a list of parameters on a Method, as
instances of class java.lang.reflect.Parameter, and there is a method
getName() in the Parameter class.

Unfortunately right now it still prints out values like 'arg0' and
'arg1', regardless of the actual names, but the idea is there.

AHS

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      02-09-2013
On Fri, 8 Feb 2013 16:10:48 -0800 (PST), Lew <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>
>What do you mean by "amanuensis"?


see http://mindprod.com/jgloss/amanuensis.html




--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      02-09-2013
On Fri, 08 Feb 2013 14:21:50 -0800, Roedy Green
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>In the olden days PL/I has a output mechanism called PUT DATA


I have written this up as a beginner student project at

http://mindprod/project/putdata.html
--
Roedy Green Canadian Mind Products http://mindprod.com
The first 90% of the code accounts for the first 90% of the development time.
The remaining 10% of the code accounts for the other 90% of the development
time.
~ Tom Cargill Ninety-ninety Law
 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      02-10-2013
On 2/9/2013 6:49 PM, Roedy Green wrote:
> On Fri, 08 Feb 2013 14:21:50 -0800, Roedy Green
> <(E-Mail Removed)> wrote, quoted or indirectly quoted
> someone who said :
>> In the olden days PL/I has a output mechanism called PUT DATA

>
> I have written this up as a beginner student project at
>
> http://mindprod/project/putdata.html


Today the feature is probably more common seen in C/C++.

With something like:

#define PRINTD(x) printf("%s=%d\n", #x, x)
#define PRINTS(x) printf("%s=%s\n", #x, x)

Arne

PS: I know that I can do:

#define PRINTD(x) printf(#x "=%d\n", x)
#define PRINTS(x) printf(#x "=%s\n", x)

but it just doesn't seem as readable to me.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
where to put load of static data? =?Utf-8?B?Q2hyaXM=?= ASP .Net 4 10-03-2005 03:37 PM
How to put gif file in Data grid...... Gill Smith ASP .Net 1 05-29-2004 03:50 AM
Put Data in DropDownList ruca ASP .Net 3 02-07-2004 01:25 AM
Put data to DataGrid in memory Sara T. ASP .Net 2 07-23-2003 06:13 PM



Advertisments