|
Quick Lists
|
|
Bug ID:
|
4151957
|
|
Votes
|
0
|
|
Synopsis
|
Proposal: null-safe field access operator
|
|
Category
|
java:specification
|
|
Reported Against
|
1.2beta3
|
|
Release Fixed
|
|
|
State
|
11-Closed,
Will Not Fix,
request for enhancement
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
|
|
Submit Date
|
24-JUN-1998
|
|
Description
|
Hi!
I am proposing a new null-safe operator for field
access in Java. I'm using "?." for the notation
in the example below:
class Base
{
Integer member;
}
...
static Integer getMember( Base b )
{
Integer result;
// Simplest way to code this function will
// throw a NullPointerException when 'b' is
// a null customer :
result = b.member;
// .. or, to avoid, the exception, some code
// must be added to explicitly check the base
// customer :
result = b == null ? null : b.member;
// My suggestion: add operator "?." which
// returns null if its left-hand-side base
// customer is null and otherwise returns the
// field referred to by the right-hand-side:
result = b?.member;
// E.g. the third assignment works like the
// second while it looks much like the first
// assignment.
// In particular, the third assignment shall
// never throw a NullPointerException.
return result;
}
Although my proposal is just for convenience and
has rather obvious workaround, I would be glad if
you took it into some consideration.
terv: Risto Lankinen
(Review ID: 34107)
======================================================================
|
|
Work Around
|
N/A
|
|
Evaluation
|
It is, as the submitter acknowledges, just a syntactic sugar. I don't find the case for it at all persuasive. The bar for adding features to Java must be set very high.
xxxxx@xxxxx 1998-07-02
|
|
Comments
|
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |