PROPOSAL: 'final' without explicit type (update) (original) (raw)

Marek Kozieł develop4lasu at gmail.com
Mon Mar 30 14:26:16 PDT 2009


AUTHOR: Lasu aka Marek Kozieł

OVERVIEW

FEATURE SUMMARY:

MAJOR ADVANTAGE: It allows people to concentrate on logic during operating on heavy generics and to use values which are more intuitive for them than variables.

MAJOR BENEFIT(s):

MAJOR DISADVANTAGE: Certainly, some people will overuse this solution. Consider operator is easier to read. It might be a problem if a person does not know how to give proper names for values.

ALTERNATIVES: Normal variables.

EXAMPLES

SIMPLE / ADVANCED EXAMPLE: public Map<String,ArrayList> readMaping(){ final map = new HashMap<String,ArrayList>(); for( final row : readLine() ){ String key = row.get(0); row.remove(0); map.put(key, row); } return map; }

public Map<String,ArrayList> readMaping(){ final map; //compile time error map= new HashMap<String,ArrayList>(); for( final row : readLine() ){ String key = row.get(0); row.remove(0); map.put(key, row); } return map; }

public class Final { static final maping = new HashMap<String, ArrayList>(); }

public class Final { static final maping = (Map<String,ArrayList>)loadMap(); }

DETAILS

SPECIFICATION: FieldDeclaration FieldDeclaration would be extended to allow omitting Type declaration if field is final and it's directly followed by assignment of new class instance creation(created object type would be used), or by Anonymous Constructors (JLS 15.9.5.1 )(direct superclass S would be used), or Enum constants preceded by EnumType (JLS 8.9) (Enum type would be used), or CastExpression (JLS 15.16) (ReferenceType would be used).

SPECIFICATION: LocalVariableDeclarationStatement (JLS 14.4) Local Variable Declaration Statements would be extended to allow omitting Type declaration if field is final and listed rules taking place:

COMPILATION: Just as today, value type only need to be determined.

TESTING: The same as final-s variables.

LIBRARY SUPPORT: No.

REFLECTIVE APIS: No.

OTHER CHANGES: No.

MIGRATION: None.

COMPATIBILITY Only code is no forward compatible.

REFERENCES RFE: Add Immutable types to Java: http://bugs.sun.com/view_bug.do?bug_id=4459053

Typedef (alias): http://bugs.sun.com/view_bug.do?bug_id=4983159

http://lasu2string.blogspot.com/2009/03/final-without-explicit-type-proposal.html



More information about the coin-dev mailing list