可能类似于问题,为什么外部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) 试图在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) 这是我的示例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方法.

这是我的示例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中,新的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对象是否有任何好的方法?
我想将一个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/
我想要一个这样的链接:当它被点击时,它会变为文本,当鼠标移出文本时,它会返回链接.
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.请帮忙.
为什么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) 我正在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 ×6
eclipse ×2
jquery ×2
base64 ×1
eclipse-jdt ×1
javascript ×1
lambda ×1
linux ×1
shell ×1
visibility ×1