permaculture playing cards
The moose likes Java in General and the fly likes is macro substitution possible in java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "is macro substitution possible in java?" Watch "is macro substitution possible in java?" New topic

is macro substitution possible in java?

vishal avad
Ranch Hand

Joined: Nov 29, 2001
Posts: 45
Hi all
Anybody has any idea how to achieve macro substitution in java.
I ve following code. Which works fine in fox pro

same thing is also possible in VB
So please let me know how to access a value inside a variable's value.
please reply asap
thx in adv
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
This isn't very easy in Java. Chances are good you'd want to reconsider your design to avoid needing to do this. But you can use reflection to achieve this sort of effect if you need to:

"I'm not back." - Bill Harding, Twister
vishal avad
Ranch Hand

Joined: Nov 29, 2001
Posts: 45
Hi Jim
Thanx It works Fine, Sorry for my repeat post of message in begineer. Actually i m a bit confused with the level of question. It wont happen again
thanx again
Mapraputa Is
Leverager of our synergies

Joined: Aug 26, 2000
Posts: 10065
Recently I was investigating macros as a way to extend a language, and here this question came
There are several interesting projects that add macro functionality to Java at various levels.
Vishal's example is simple abbreviation (an advanced variant allows parameters), Jatha can do that.
More interesting applications are where macros are a tool for building abstractions. OpenJava extends Java's reflection system by providing a programmer with "metaobject" abstraction, via which he can query a state of the program (classes, methods...) and modify it at compile time, thus adding new features to the language. (syntax extensions have only limited support).
Even more advanced approach is to allow programmer extend syntax of the language with new constructs. Java Syntactic Extender (JSE) is one such project, Metamorphic Syntax Macros is another. (the latter paper has a nice general overview of macro functionality). You can, for example, amend Java with forEach operator:
forEach(Task elt in tasks)
and whose expansion would be:
Iterator i = tasks.iterator();
while (i.hasNext()) {
   Task elt = (Task);
(this example is stolen from JSE paper)
As an extreme manifestation of power of macros, totally new, domain-specific languages can be build on base of a host language. On base of Java and "metamorphic syntax macros", a DSL for Web services was built. The Jakarta Tool Set (JTS) provides tools for creating domain specific languages.
[ August 11, 2002: Message edited by: Mapraputa Is ]

Uncontrolled vocabularies
"I try my best to make *all* my posts nice, even when I feel upset" -- Philippe Maquet
TJ Hylton

Joined: Jul 27, 2002
Posts: 12
I have been programming in java for only three months so at the risk of sounding dumb I ask, what is macros and what do they do?

TJ Hylton
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
macro. Map's links above are definitely worth a look.
I agree. Here's the link:
subject: is macro substitution possible in java?
jQuery in Action, 3rd edition