@groovy.transform.TypeChecked
abstract class Entity {
...
double getMass() {
...
}
...
}
@groovy.transform.TypeChecked
abstract class Location {
...
Entity[] getContent() {
...
}
...
}
@groovy.transform.TypeChecked
abstract class Container {...} //inherits, somehow, from both Location and Entity
@groovy.transform.TypeChecked
class Main {
void main() {
double x
Container c = new Chest() //Chest extends Container
Entity e = c
x = e.mass
Location l = c
x = l.content //Programmer error, should throw compile-time error
}
}
Run Code Online (Sandbox Code Playgroud)
从本质上讲,有没有办法实现这一点,而不会牺牲以下三个属性轮廓中的任何一个main(): …