接口内的嵌套类 [英] Nested class inside an interface

查看:72
本文介绍了接口内的嵌套类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java编译器允许我在Interface中编写一个Class定义。是否有任何特定用途?

The java compiler allows me write a Class definition inside an Interface . Are there any specific uses of this ?

interface ClassInterface {

  void returnSomething();
  int x = 10;

  class SomeClass {
    private int y;

    private void classDoingSomething() {         
    }
  }
}

请解释。

推荐答案

您可以使用它将某种类型紧密绑定到接口。阅读页面有关更多信息以及在界面中定义类的示例。

You would use it to tightly bind a certain type to an interface. Read This page for further information and an example of defining a class inside an interface.

这篇关于接口内的嵌套类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆