为了账号安全,请及时绑定邮箱和手机立即绑定

实现接口时出现错误“无法降低继承方法的可见性”

实现接口时出现错误“无法降低继承方法的可见性”

慕妹3242003 2021-08-04 16:44:12
我刚刚安装了 ta4j Technical Analysis lib 。它有一个名为TimeSeries. 当我尝试实现第一种方法时TimeSeriesString getName()我收到以下错误:无法降低来自 TimeSeries implaments org.ta4jcore.Timeserios.GetName 的内在方法的可见性我的代码import org.ta4j.core.*;public class cMyChartVal implements TimeSeries {       /**     * @return the name of the series     */    String getName()    {        return "TestSet";    }    .....    .....}TimeSeries 接口类package org.ta4j.core;import java.io.Serializable;import java.time.format.DateTimeFormatter;import java.util.List;/** * Sequence of {@link Bar bars} separated by a predefined period (e.g. 15 minutes, 1 day, etc.) * </p> * Notably, a {@link TimeSeries time series} can be: * <ul> *     <li>the base of {@link Indicator indicator} calculations *     <li>constrained between begin and end indexes (e.g. for some backtesting cases) *     <li>limited to a fixed number of bars (e.g. for actual trading) * </ul> */public interface TimeSeries extends Serializable {    /**     * @return the name of the series     */    String getName();    /**     * @param i an index     * @return the bar at the i-th position     */    Bar getBar(int i);    /**     * @return the first bar of the series     */    default Bar getFirstBar() {        return getBar(getBeginIndex());    }    /**     * @return the last bar of the series     */    default Bar getLastBar() {        return getBar(getEndIndex());    }    /**     * @return the number of bars in the series     */    int getBarCount();    /**     * @return true if the series is empty, false otherwise     */    default boolean isEmpty() {        return getBarCount() == 0;    }
查看完整描述

1 回答

?
HUH函数

TA贡献1836条经验 获得超4个赞

接口中的所有方法声明,包括静态方法,都是隐式公开的。它通常被省略。


实现类应该保留这个修饰符,而不是使用默认的类方法 modifer( package level)。


您可以将其更改为:


public String getName()

{

    return "TestSet";

}


查看完整回答
反对 回复 2021-08-04
  • 1 回答
  • 0 关注
  • 289 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号