我需要開發一個只能實現一次的接口。如果其他類嘗試在同一個項目中實現相同的接口,則不應允許或發生錯誤。如何限制java接口在多個類中實現
interface A {
void someMethod();
}
class B implements A {
void someMethod() {
// implementation here
}
}
現在我想限制其他類來實現接口一個
class c implements A { //this should not allowed in this project
}
是否有可能開發這種接口的?任何人都可以提出,我該如何去做到這一點?
你爲什麼要這麼做?製作一個只能實現一次的界面有什麼可能呢? – Yuushi