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

compile error

 
sahan thinusha
Greenhorn
Posts: 10
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

"Example.java:10: error: variable d might not have been initialized"
why?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine what happens if a > 2.

Is this a typo: "if(a<2)d='j'; if(a<2)d='k';" ? As it is, the first statement will have no effect.
 
Tomek Ziolkowski
Greenhorn
Posts: 9
Eclipse IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'd' variable must be initialised outside of the if condition or there must be added 'else' similar as with initialisation of 'c' to any of the conditions at lines 7,8,9.It seems that a compiler doesn't know whether an if condition is passed at line 10 and thus takes a possibility that this condition may not be true.
 
sahan thinusha
Greenhorn
Posts: 10
Android Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry my mistake.this is the code.
sahan thinusha wrote:

"Example.java:10: error: variable d might not have been initialized"
why?
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the compiler is too stupid to see that all cases are covered. We see it, but because there are three different if-statements the compiler doesn't.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50245
79
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t call the compiler stupid. It is very difficult to program a compiler to verify that those cases cover all possibilities.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Not smart enough for this task" is the same as "too stupid for this task", isn't it?
 
Paul Witten
Ranch Hand
Posts: 86
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:"Not smart enough for this task" is the same as "too stupid for this task", isn't it?

I call it too smart to get involved.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50245
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with Paul Witten. It would be possible to write a compiler which can cope with all sorts of daft code, possibly running through all paths of execution to test whether the value has or has not changed from 2. Of course, it could then take several minutes to compile a 50‑line class, so Paul Witten’s comment is spot on.
 
Paul Witten
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote: Of course, it could then take several minutes to compile a 50‑line class

All joking aside and all trivial code aside, the Big World does have to build systems such as Weblogic Server which already takes a couple of hours on a good box. It's unimaginable how that logic overhead would affect large projects. It might make them unbuildable in our lifetimes. I suppose that's good job security. Or maybe the opposite. "OK, we kicked off the build. You're now laid off because by the time the build is done you'll be 80 years old."

 
Campbell Ritchie
Sheriff
Pie
Posts: 50245
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Witten wrote: . . . It's unimaginable how that logic overhead would affect large projects. It might make them unbuildable in our lifetimes. . . .
You could probably apply that to Trojans, etc, and we could build anti‑malware programs quicker than the malware.

Joking aside, it would probably run in exponential complexity, so 80 years is quite feasible.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic