PUT DATA

R

Roedy Green

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

Expresses Javesquely it would look like this:

out.putd ( xlow, xhigh);

It would output

xlow=23.4 xhigh=200.0

(There was also a keyword/value input method. It was mainly helpful
in debugging.)
I could see how you could implement it in a preprocessor or
amanuensis, but can you do it with a pure Java method? What if you
warp the syntax brutally to hide info with annotations?

--
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
 
A

Arne Vajhøj

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

Expresses Javesquely it would look like this:

out.putd ( xlow, xhigh);

It would output

xlow=23.4 xhigh=200.0

(There was also a keyword/value input method. It was mainly helpful
in debugging.)
I could see how you could implement it in a preprocessor or
amanuensis, but can you do it with a pure Java method? What if you
warp the syntax brutally to hide info with annotations?

xlow and xhigh seems to be variable names.

They do not even exist at runtime for local variables.

So: no - impossible.

And annotations are put on types not on instances.

Arne
 
L

Lew

Roedy said:
In the olden days PL/I has a output mechanism called PUT DATA

Expresses Javesquely it would look like this:

out.putd ( xlow, xhigh);

It would output

xlow=23.4 xhigh=200.0

(There was also a keyword/value input method. It was mainly helpful
in debugging.)

I could see how you could implement it in a preprocessor or
amanuensis, but can you do it with a pure Java method?

What do you mean by "amanuensis"?
 
A

Arved Sandstrom

????

X a;
X b;

what annotation are you suggesting that I use two distinguish between
the two X'es?

Arne
This suddenly got confusing. I believe we all know that we can have one
set of annotations on

X a;

and a completely different set of annotations on

X b;

Clearly the annotations must be appropriate for type 'X', but they are
separately associated to 'a' and to 'b'.

AHS
 
A

Arne Vajhøj

This suddenly got confusing. I believe we all know that we can have one
set of annotations on

X a;

and a completely different set of annotations on

X b;

Clearly the annotations must be appropriate for type 'X', but they are
separately associated to 'a' and to 'b'.

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

Arne
 
L

Lew

Arne said:
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?"
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?
 
L

Lew

Lew said:
I don't understand your question "How do I get it in test?"



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?

public void test( @Nullable Foo x, @NotNull Bar y)
{ ... }
 
A

Arne Vajhøj

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

Arne
 
L

Lew

Arne said:
How do I inside the test method retrieve the different
annotations on a an b?



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

Arne Vajhøj

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
 
A

Arved Sandstrom

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
 
A

Arne Vajhøj

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

StringBuilder for byte[] 11
video cards for Java 1
ctrl-c ctril-v 14
jdk 1.7.0_13 is out 4
abbreviated generic syntax 14
creating byte[] with subfields 14
refactoring problem 34
regex reserved chars 23

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top