0

我无法在网上的其他任何地方找到如何做到这一点,但我确信这很容易做到。不过,我主要是自学成才,我想开始学习正确地记录我的代码。这个在 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 文件然后使用它时,它才不起作用。我必须单击导出屏幕上的选项吗?

4

1 回答 1

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);

您可以对自己对象的方法执行相同的操作。

于 2018-12-18T17:19:08.173 回答