【问题标题】:Eclipse Object Info Box on Custom Objects自定义对象上的 Eclipse 对象信息框
【发布时间】:2019-05-19 02:40:18
【问题描述】:

我在网上的其他任何地方都找不到如何做到这一点,但我确信这很容易做到。不过,我主要是自学成才,我想开始学习正确地记录我的代码。这个在 Eclipse 中弹出的“黄色框”,其中包含有关该方法的信息 - 我希望它在自定义对象上弹出。对于下面的示例,我有一个名为“System Properties”的自定义类和一个名为“getOs”的方法,但是当我悬停该选项时,没有信息出现。 如何向我的对象添加信息?

此图为黄色框

这张图片显示我的对象上缺少一个“黄色框”

最后是我的自定义对象代码...

public class SystemProperties {

    private String os;

    public SystemProperties() {
        this.os = setOs();
    }

    private String setOs() {
        String osName = System.getProperty("os.name");
        if(osName.toLowerCase().contains("window"))
            return "Windows";
        else if(osName.toLowerCase().contains("mac"))
            return "Mac";
        else
            return "Linux";

    }

    /**
     * Method to grab the OS the user is running from
     * @return String - the os
     */
    public String getOs() {
        return this.os;
    }

}

提前感谢您的时间和知识。 :)

编辑: 当我导入自定义对象的项目时,它工作得很好。仅当我将自定义类的项目导出到 jar 文件然后使用它时,它才不起作用。我必须点击导出屏幕上的选项吗?

【问题讨论】:

    标签: java object box yellow


    【解决方案1】:

    Eclipse 从内置对象中的方法上面的注释中获取信息。

    看到这个:

        /**
     * Returns <tt>true</tt> if this map contains a mapping for the specified
     * key.  More formally, returns <tt>true</tt> if and only if
     * this map contains a mapping for a key <tt>k</tt> such that
     * <tt>(key==null ? k==null : key.equals(k))</tt>.  (There can be
     * at most one such mapping.)
     *
     * @param key key whose presence in this map is to be tested
     * @return <tt>true</tt> if this map contains a mapping for the specified
     *         key
     * @throws ClassCastException if the key is of an inappropriate type for
     *         this map
     * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
     * @throws NullPointerException if the specified key is null and this map
     *         does not permit null keys
     * (<a href="{@docRoot}/java/util/Collection.html#optional-restrictions">optional</a>)
     */
     boolean containsKey(Object key);
    

    你可以对你自己的对象的方法做同样的事情。

    【讨论】:

    • 我看到您实际上已经这样做了。我不确定为什么它不适合你。它对我有用。
    • 你会不会碰巧有一个网站的链接来记​​录这个?
    猜你喜欢
    • 1970-01-01
    • 2014-03-29
    • 2017-05-12
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多