Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is the purpose for allowing local variables as abstract ?

 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm truly sorry if my question has been answered already, but that thing just came into my mind.

As the topic, what is the main purpose for allowing local variables as abstract ? Is it just solely for abstract class/method so that programmers can leave such variables with no initialization ?

What I understand is, instance variables are automatically assigned to default values if no initialization but for local, we must declare their values explicitly. So, the main purpose for local can be abstract is, just for abstract class/method or is there other reasons ?

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Local variables cannot be abstract. The only modifier allowed for local variables is final

As a matter of fact, the abstract abstract modifier is used for classes or methods respectively, not for variables.
 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastian Janisch wrote:Local variables cannot be abstract. The only modifier allowed for local variables is final

As a matter of fact, the abstract abstract modifier is used for classes or methods respectively, not for variables.


Hi, thanks for your quick response, but local variables certainly can be abstract.



That's why I'm wondering why it's allowed, no idea how it's useful in what situation except abstract class/method
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



some mysterious thing occurs ? I use NetBeans 6.7 and Java 1.6.0_13 on Mac. I swear by god that I never change, just compile and get this successful message.
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just tried with Eclipse Ganymede using Java 1.6.0_14 on Ubuntu and it does not compile.

I get the exact same error as Mike.

Have you tried compiling from the command line/terminal? Perhaps NetBeans is suppressing a warning and you are not running the class you think you are running.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just about to say that NetBeans maybe has a precompiler that strips out things that don't make sense ...
 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason Irwin wrote:Just tried with Eclipse Ganymede using Java 1.6.0_14 on Ubuntu and it does not compile.

I get the exact same error as Mike.

Have you tried compiling from the command line/terminal? Perhaps NetBeans is suppressing a warning and you are not running the class you think you are running.


Hi Jason, you are absolutely correct, as I've tried in cmd and get the same error.
Hmm, why NetBeans is not giving such error ? Is it like NetBeans is not as reliable as Eclipse or am I missing something?

For the thing you said that it's not the class that I think it's, could not be. Because it's showing other parts of the program and so, I'm pretty sure it's as what it should be. In fact, I'm just doing as a practice myself for my SCJP 6 exam which is on 14th next month, studying the Inner Class related question using "SCJP 6 Study Guide by Kathy Sierra & Bert Bates". This is my full code for the whole program.



anyway, thanks a lot to you guys
really appreciate your very fast and helpful response + advice
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I means was, if you had just added "abstract", then you could actually be running an older .class accidentally.

Why NetBeans doesn't report it beats me - I have never used NetBeans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic