2013年9月23日星期一

Java static inner classes to correct rumors

I see a lot online that , this points to instances of class ! Therefore, static inner classes can use this.
I do not know why you say that endured , I felt these words wrong, to say the least , with a code
If I am wrong, correct me ask , do not spray !

public class A {
private static class B{
public int a ;
public int b ;
public B a(int a){ this.a = a ; return this;}
public B b(int val){ b = val ; return this;}
}
public static void main(String[]args){
B a = new B();
B b = new B();
a.a = 1 ;
b.a = 2 ;
System.out.println(a.a+":"+b.a);
B c ;
c = a.a(3).b(5);
System.out.println(a.a+":"+b.a+":"+a.a+":"+c.b);
}
}


wanted then , my static inner class B uses this!

others may say static inner classes can not have this deep has its meaning, I do not know slightly.
If I am wrong, correct me ask , do not spray !

welcome to observe the post !
------ Solution ---------------------------------------- ----
Honestly, I can not see what is wrong with your code / special and what you want to express

------ Solution ------------------------------------ --------
say is that static methods / code block where you can not use this. How to become a static class ?
------ Solution ---------------------------------------- ----
static inner class can use this , but static methods, static block is not used .
------ Solution ---------------------------------------- ----
public static B a (int a) {
this.a = a; return this;}
public B b (int val) {
b = val; return this;}
}
If you write so here is wrong.
------ For reference only -------------------------------------- -


without meaning to , just want to prove that under the static function , the pointer can be used thi !
------ For reference only -------------------------------------- -


Oh, do not spray , man, I was visiting the post , I wandered a Java static inner class post to see,
This person path is as follows : http://bbs.csdn.net/topics/390597370?page=1 # post-395621873
I give you a screenshot


figure inside, is he talking about Java static inner classes use it, talked about the inner class to write the words .
---------------------
I followed the post, search find many Java static inner classes on the post, then looked and found essentially reproduced with each other !
That is, basically this problem, so , made ​​the stickers , confirmed under static inner classes can be used in this ...
------ For reference only --- ------------------------------------
Fortunately , not to 500 .
------ For reference only ---------------------------------------


is the reason !
------ For reference only -------------------------------------- -


500 bar small case!
------ For reference only -------------------------------------- -


I wrote how wrong with it ?
------ For reference only -------------------------------------- -

  
I wrote how wrong with it ?  
static class can use this, in a static class static method can not use this

没有评论:

发表评论