-
Enhancement
-
Resolution: Won't Fix
-
P5
-
None
-
7
-
x86
-
linux
A DESCRIPTION OF THE REQUEST :
This is not a new idea: struts 1.x (and probably other frameworks) implements this for accessing inner members of javabeans with Nested tags. Would be cool to have a similar thing in java. I'm sorry if a similar thing already exist (!): looked for an hour before filling.
The concept is to permit unbloated way to access public members of a specified object in constructors and methods, changing the scope in a local block. For example, instead of:
obj.field=1;
obj.foo();
...
introduce a keyword "nest" that permits this:
nest obj {
field=1;
foo();
...
}
Default ("root") scope could be introduce using a c++ similar notation with "::". Follows a more sophisticated example:
class C {
int a;
int b;
}
class D {
int b;
C c;
void foo() {
nest c {
a++; // change a in C
b++; // change b in C
::b++; // change b in D
}
}
}
JUSTIFICATION :
Rationale: permits code more readable in all situations when is necessary to do lot of accesses on member objects. It could even lead to code that almost resembles full multiple inheritance (!). Here an example of what i mean:
class C {
int a;
}
interface InterfaceD {
void foo();
}
class D implements InterfaceD {
int a;
void foo();
}
class E extends C implements InterfaceD {
D d;
void foo() nest d { // Implements foo() and permits writing code as i would on d (!)
foo(); // call foo of d (!)
a++; // change a in D
::a++; // change a in C
}
}
This is not a new idea: struts 1.x (and probably other frameworks) implements this for accessing inner members of javabeans with Nested tags. Would be cool to have a similar thing in java. I'm sorry if a similar thing already exist (!): looked for an hour before filling.
The concept is to permit unbloated way to access public members of a specified object in constructors and methods, changing the scope in a local block. For example, instead of:
obj.field=1;
obj.foo();
...
introduce a keyword "nest" that permits this:
nest obj {
field=1;
foo();
...
}
Default ("root") scope could be introduce using a c++ similar notation with "::". Follows a more sophisticated example:
class C {
int a;
int b;
}
class D {
int b;
C c;
void foo() {
nest c {
a++; // change a in C
b++; // change b in C
::b++; // change b in D
}
}
}
JUSTIFICATION :
Rationale: permits code more readable in all situations when is necessary to do lot of accesses on member objects. It could even lead to code that almost resembles full multiple inheritance (!). Here an example of what i mean:
class C {
int a;
}
interface InterfaceD {
void foo();
}
class D implements InterfaceD {
int a;
void foo();
}
class E extends C implements InterfaceD {
D d;
void foo() nest d { // Implements foo() and permits writing code as i would on d (!)
foo(); // call foo of d (!)
a++; // change a in D
::a++; // change a in C
}
}
- relates to
-
JDK-4465496 Add Syntax Similar to Pascal's "with" Statement
-
- Closed
-
-
JDK-4191243 Method forwarding - Subclassing without subtyping
-
- Closed
-