Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367885 - [xtend] Support final field declarations
Summary: [xtend] Support final field declarations
Status: CLOSED FIXED
Alias: None
Product: Xtend
Classification: Tools
Component: Core (show other bugs)
Version: 2.2.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: M7   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 371958 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-01-04 14:50 EST by Sebastian Zarnekow CLA
Modified: 2017-10-31 11:26 EDT (History)
4 users (show)

See Also:
sebastian.zarnekow: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.