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

In interface if any variable is declared then no need to initialize.

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java class If any variable is declared then no need to initialize the variable. But In interface if any variable is declared then no need to initialize.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jacob deiter wrote:In Java class If any variable is declared then no need to initialize the variable. But In interface if any variable is declared then no need to initialize.


per the JLS, every "variable" declared in an interface is implicitly public, static, and final.
per the JLS, 9.3.1: Every field in the body of an interface must have an initialization expression, which need not be a constant expression. The variable initializer is evaluated and the assignment performed exactly once, when the interface is initialized.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic