4
วิธีการสร้างอินสแตนซ์คลาสภายในที่ไม่คงที่ภายในวิธีการคงที่?
ฉันมีรหัสต่อไปนี้: public class MyClass { class Inner { int s, e, p; } public static void main(String args[]) { Inner in; } } ถึงส่วนนี้รหัสก็ใช้ได้ แต่ฉันไม่สามารถสร้างอินสแตนซ์ 'in' ภายในวิธีการหลักเหมือนin = new Inner()ที่แสดงnon static field cannot be referenced in static contextได้ ฉันจะทำอย่างไร? ฉันไม่ต้องการที่จะทำให้ฉันInnerระดับคงที่
122
java
static
inner-classes