java - 这个界面有什么问题?
问题描述
接口可以包含正文吗?帮我解决这部分
public interface Figures
{
public void printMessage (String s)
{
System.out.println ("This figure is " + s);
}
public double area (); // to calculate the area of the figure
}
解决方案
default
从 Java 8 开始,我们可以使用关键字为接口方法提供默认植入
public interface Figures
{
public default void printMessage (String s)
{
System.out.println ("This figure is " + s);
}
public double area (); // to calculate the area of the figure
}
推荐阅读
- amazon-web-services - Docker Swarm 使用 rexray/ebs 在 AWS EBS 中运行 TeamCity 以实现驱动器持久性的问题
- javascript - 从firebase注销后从google注销
- google-oauth - Google Oauth signin page returning 500 error with electron
- python - 计算 N 维的简并状态
- reactjs - 反应路由。如何生成地址
- javascript - 节点红色 ReferenceError:la 未定义(第 1 行,第 8 列)
- python - 使用 groupby idcolumn 和 cumsum of timedelta 在时间序列中标记“trips”
- angular - 在使用响应式表单时将模板引用变量绑定到 ngModel
- postgresql - 如何在 Postgres 中获取简短的日期名称,例如“Mon”、“Tue”、“Wed”
- flutter - 将回调从模型传递到 Flutter 中的 GestureDetector 的语法