Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

declaring methods

 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why cannot we declare a method inside a method in java?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you could create it, how would you call this method?
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What would be practical use of such method?

You can make method inner classes and have methods defined there ...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:If you could create it, how would you call this method?

(Same way as any other method :)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martin Vanyavchich wrote:What would be practical use of such method?

Scope overriding.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:
Paul Sturrock wrote:If you could create it, how would you call this method?

(Same way as any other method :)


How could you call a public method that is a member of another method?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be method-local, just like in a nested JavaScript function.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't that restrict the language? I'd have to implement the same "inner" method redundantly accross a bunch of classes. OK it works with a weakly typed scripting language but I can't see how it would give any benefit to a strongly typed language?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't claim it would be a benefit--just how it would work. I think it'd be a bad idea in Java.
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do that sort of thing in Scala.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:I didn't claim it would be a benefit--just how it would work. I think it'd be a bad idea in Java.


Fair enough. I just couldn't think of any purpose of this either.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic