This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Compilation error on different line number

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In the above code, you get a compilation error on line 5 saying comma is expected instead of semicolon.
However, I was expecting the error on line 6 as I was modifying a final variable from a parent class.  While I can see, if I change the code to :


There is no compilation error. Makes sense!
But the line number of the compilation error is confusing to me in the sense such kind of questions are asked in OCAJP where we are expected to know the line number where the compilation error comes.

Do you know any other example similar to this one? Thanks!
 
Marshal
Posts: 65069
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That tells you how difficult it is to write good compiler error messages. Yes, you would have expected the compiler to complain about trying to reassign a final field, but that is a statement, and statements are only permitted in methods, constructors, initialiser, etc. That is code lying free in the class, where only declarations are permitted. If it is a declaration, it hasn't got a type, so the likeliest error is that it is part of the previous declaration. It will compile asYou are declaring the same field twice in two classes, which is dubious and error‑prone design, and you are declaring two fields in the same line, which is poor style. In fact both those offences against good programming should be banned everywhere . . . except in cert. exams
 
Neha Agnihotri
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks for the explanation. It's much clear now.

PS: I am really amazed how quickly I get answers/explanation on this forum. A big Thank You to all of you!
 
Campbell Ritchie
Marshal
Posts: 65069
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Neha Agnihotri wrote:. . . thanks . . . Thank You . . .

That's a pleasure We try to provide a good service.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!