Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367885

Summary: [xtend] Support final field declarations
Product: [Tools] Xtend Reporter: Sebastian Zarnekow <sebastian.zarnekow>
Component: CoreAssignee: Project Inbox <xtend-inbox>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: consiliens, harshad.rj, sven.efftinge, thsoft
Version: 2.2.0Flags: sebastian.zarnekow: juno+
Target Milestone: M7   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sebastian Zarnekow CLA 2012-01-04 14:50:43 EST
Semantics should be the same as in Java. A final fields may be written ones in a constructor or it has to have an initializer.

See also bug 343103
Comment 1 Dénes Harmath CLA 2012-02-17 05:41:54 EST
Immutable fields are ubiquitous in the functional, composition-oriented programming style which Xtend itself encourages. (For some arguments, see http://javarizon.wordpress.com/2010/06/26/why-every-java-field-should-have-been-final-by-default among many others.) I know Xtend's design principle is to stay as close to Java as possible, but I'd propose, if it's already unfortunately not part of the language by design, to make it as easy to declare as possible (e.g. use another keyword like 'const' which is shorter and doesn't overload the other meanings of the final keyword).
Comment 2 Sven Efftinge CLA 2012-04-10 16:41:54 EDT
Proposed syntax:

class Person {
  val myNumber = 42 // final
  var foo = "default" // non-final
  String anotherFoo = "default" // non-final
  static val MY_CONSTANT = "foo bar baz"
  var String name
}
Comment 3 Sven Efftinge CLA 2012-04-10 16:42:26 EDT
*** Bug 371958 has been marked as a duplicate of this bug. ***
Comment 4 Sven Efftinge CLA 2012-04-11 08:03:31 EDT
pushed to master
Comment 5 Eclipse Webmaster CLA 2017-10-31 11:26:33 EDT
Requested via bug 522520.

-M.