0

So say I had a variable like this:

String var = "name"

instead of making a method like so -

Public void name{
    System.out.println("This is a method called name");
}

I want to create like this -

Public void var{
    System.out.println("This is a method called name");
}

but instead of the method being called var, I want it to be called name

The reason I need this:

I'm building a lexer/parser, and this reads methods from another (made up) language, so I want to transfer these methods into java with the same names to be called upon later on

Summer
  • 23
  • 1
  • 7
  • 1
    Tried to make something like this some time ago. Didn't find any way :/ – Mibac May 09 '15 at 20:52
  • @Jyr Basically, I'm building a lexer/parser, so I have methods from another language and want to transfer these to java with the same names – Summer May 09 '15 at 20:53
  • 2
    Why you need this ? You can use reflection or under Java 8 lambdas/functional references. Please provide more detail why you need this ... – kulatamicuda May 09 '15 at 20:55
  • 1
    Your question smells of being a classic [XY Problem](http://mywiki.wooledge.org/XyProblem) where you ask how to solve a specific code problem when the best solution is to use a completely different approach. Better that you tell us the overall problem that you're trying to solve rather than how you're currently trying to solve it. I think that you may be ascribing more power to method names than they really have. – Hovercraft Full Of Eels May 09 '15 at 20:55
  • @kulatamicuda I've added some explanation as to why I think I need this – Summer May 09 '15 at 21:00
  • 1
    @Summer I would use different approach. Look here http://en.wikipedia.org/wiki/Interpreter_pattern , as Hovercraft has written, your problem smels liike classic XY problem. – kulatamicuda May 09 '15 at 21:01
  • @kulatamicuda Interpreter pattern looks as though it will work from a glance, thank you!! – Summer May 09 '15 at 21:03
  • Nice work @kulatamicuda! – Hovercraft Full Of Eels May 09 '15 at 21:15

0 Answers0