Reputation: 123
I would know if exists "macro substitution" in java... I'm developing a system in Android that was originally developed in Visual Fox Pro, now I have to turn some methods with "macro substitution" to Java Language.
How Can I achieve it?
Upvotes: 2
Views: 3526
Reputation: 1
I'm familiar with macro substitution in Visual FoxPro. It essentially allows the programmer to reference a variable's value with a variable name evaluated at runtime rather than at compile time:
myvar = "MyVariable"
&myvar = 42
? myvar
? &myvar
? MyVariable
Output:
MyVariable
42
42
This code dynamically creates a variable at runtime named MyVariable
.
This is possible because Visual FoxPro supports dynamic typing or "late binding", since it is an interpreted language rather than compiled. Java doesn't support dynamic typing directly. The method that seems to be preferred by Java developers is to associate the variable name and its value using a Map. See the thread How do I dynamically name objects in Java?.
Upvotes: 0
Reputation: 12339
You are probably asking about macro expansion, where you enter a macro with an argument and it expands to compilable Java code.
The simple answer is no.
Please see Alternatives to macro substitution in java for another way to simulate macro expansion.
Most IDEs (Eclipse is my poison of choice) will do something parallel to macro expansion. If you type foreach and Ctrl-Space, it will expand it to the for-loop Java with its best guess as to what you're iterating over.
Upvotes: 2