小编and*_*dyf的帖子

为什么嵌套子类可以访问其父类的私有成员,但孙子不能?

可能类似于问题,为什么外部Java类可以访问内部类私有成员?使用子类中的super关键字访问超类私有字段.

但是存在一些差异:子类可以访问其父级(并且只有最近的父级)的私有成员.

鉴于以下示例代码:

public class T {

    private int t;

    class T1 {
        private int t1;

        public void test() {
            System.out.println(t);
        }
    }

    class T2 extends T1 {

        private int t2;

        public void test() {
            System.out.println(t);
            System.out.println(super.t1);
            System.out.println(this.t2);
        }
    }

    class T3 extends T2 {

        public void test() {
            System.out.println(t);
            System.out.println(super.t1); // NG: t1 Compile error! Why?
            System.out.println(super.t2); // OK: t2 OK
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

java visibility inner-classes

50
推荐指数
3
解决办法
4012
查看次数

解码base64:输入无效

试图在GNU/Linux上解码base64文件,我得到"base64:无效输入".

$ base64 test.zip | base64 -d > test2.zip
base64: invalid input
$ ll test*
-rw-r--r-- 1 user grp 152 19 11:41 test.zip
-rw-r--r-- 1 user grp  57 19 11:42 test2.zip
Run Code Online (Sandbox Code Playgroud)

我尝试了dos2unix命令,但它没有帮助.

我的base64版本:

$ base64 --version
base64 (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written …
Run Code Online (Sandbox Code Playgroud)

linux shell base64

33
推荐指数
2
解决办法
4万
查看次数

Eclipse - `open call hierarchy`停止在lambda链中搜索

这是我的示例java代码:

public class Test {

    public static void main(String[] args) {
        methodDepth0(
            ()->
                methodDepth1(
                    ()->
                        methodDepth2()
                )
        );
    }

    static Object methodDepth2() {
        return null;
    }

    interface MyIF {
        void call();
    }

    static void methodDepth0(MyIF myIf){
        myIf.call();
    }

    interface MyIF2 {
        void call();
    }

    static void methodDepth1(MyIF2 myIf2){
        myIf2.call();
    }
}
Run Code Online (Sandbox Code Playgroud)

当我methodDepth2()从Eclipse(4.4)打开方法的调用层次结构时, open call hierarchy停止搜索下一个调用者: 打开调用层次结构停止搜索下一个调用方法

我期望的是打开方法的调用层次结构,methodDepth1()直到该main方法. 打开方法<code> methodDepth1()</ code>的调用层次结构,直到<code> main </ code>方法显示

java eclipse lambda call-hierarchy

20
推荐指数
1
解决办法
779
查看次数

Eclipse - `open call hierarchy`得到了错误的结果

这是我的示例java代码:

public class Test {
    public static void foo() {
        Foo.InnerKey key = new Foo.InnerKey();
        getInstance().query(key);
    }

    public static void bar() {
        Bar.InnerKey key = new Bar.InnerKey();
        getInstance().query(key);
    }

    public static MyIF getInstance(){
        // TODO code to get instance
        return null;
    }

}


interface MyIF {
    public void query(Foo.InnerKey key); // Method to open call hierarchy
    public void query(Bar.InnerKey key);
}


class Foo {
    static class InnerKey  {}
}

class Bar {
    static class InnerKey {}
}
Run Code Online (Sandbox Code Playgroud)

当我query(Foo.InnerKey key) …

java eclipse eclipse-jdt

18
推荐指数
1
解决办法
1114
查看次数

是另一个bigDecimal.toString()的BigDecimal总是等于?

在Java中,新的BigDecimal来自另一个bigDecimal.toString()总是等于?例如

    BigDecimal a = new BigDecimal("1.23");
    BigDecimal b = new BigDecimal(a.toString());

    System.out.println(a.compareTo(b) == 0); // always true?
Run Code Online (Sandbox Code Playgroud)

我知道BigDecimal是不可变的,但我想知道cloneBigDecimal对象是否有任何好的方法?

java

11
推荐指数
3
解决办法
9984
查看次数

正确的方法将html解析为jQuery对象

我想将一个html字符串解析为jQuery对象,然后按ID查找一个元素.

我尝试了3种方法,但只有最后一种方法.我不知道为什么其他人不行?

var html = "<html><body><div id='main'></div></body></html>";

// Not work, return 0
console.log($(html).find('#main').length); 
// Not work, return 0
console.log($($.parseHTML(html)).find('#main').length); 
// Works, return 1
console.log($("<html/>").html(html).find('#main').length); 
Run Code Online (Sandbox Code Playgroud)

以下是示例:http: //jsfiddle.net/nbyofkam/2/

javascript jquery

9
推荐指数
2
解决办法
2万
查看次数

jQuery - `on`事件在jQuery.replaceWith之后不起作用

我想要一个这样的链接:当它被点击时,它会变为文本,当鼠标移出文本时,它会返回链接.

HTML:

    <a href="#">click me and change to text</a>
Run Code Online (Sandbox Code Playgroud)

JS:

    $("a").on('click',function(){
        var $lnk = $(this);
        var $replace = $('<span>');
        $replace.text($lnk.text());
        // Link to Text
        $lnk.replaceWith($replace);
        // Text to Link
        $replace.one('mouseout',function(){
            $replace.replaceWith($lnk);
        });
        return false;
    });
Run Code Online (Sandbox Code Playgroud)

该代码仅适用于第一次.似乎$("a").on("click",function(){})没有工作replaceWith.

小提琴:http://jsfiddle.net/uABC9/4/

我正在使用jQuery 1.10.1并测试了FF和Chrome.请帮忙.

jquery

8
推荐指数
1
解决办法
2361
查看次数

为什么java + =得到错误的结果,我该如何防止这种情况?

为什么java +=会得到错误的结果,我该如何防止这个问题呢?(例如warning在IDE中显示的任何方式?)

我尝试了eclipse和IntelliJ,但都没有显示任何警告.

示例代码:

    {
        long a = 20000000000000000L;
        double b = 90.0;
        a += b;
        System.out.println(a); // 20000000000000088 NG
    }

    {
        long a = 10000000000000000L;
        double b = 90.0;
        a += b;
        System.out.println(a); // 10000000000000090 OK
    }

    {
        long a = 20000000000000000L;
        double b = 90.0;
        a += (long) b;
        System.out.println(a); // 20000000000000090 OK
    }
Run Code Online (Sandbox Code Playgroud)

java

8
推荐指数
1
解决办法
186
查看次数

神圣的ConcurrentModificationException数

我正在ConcurrentModificationException使用以下代码测试集合:

public static void main(String[] args) {
    ArrayList<String> list = new ArrayList<String>();
    list.add("a");
    list.add("b");
    list.add("c");

    for (String s : list) {
     // if (s.equals("a")) { // ConcurrentModificationException!
        if (s.equals("b")) { // -->> Magic number, NO Exception, Why? 
     // if (s.equals("c")) { // ConcurrentModificationException!
            list.remove(s);
        }
    }
    System.out.println(list);
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么删除"b"可以,但其他人NG?

java

3
推荐指数
1
解决办法
103
查看次数