Discover advantages of anonymous class in java, include the articles, news, trends, analysis and practical advice about advantages of anonymous class in java on alibabacloud.com
An overview: An object without a name, or an object that has no assigned value to any variable. An anonymous object is when an object is created, only the statement that created the object (the new object type), and there is no variable that receives the object.For example:Person class:public class Person { public void eat(){ System.out.println("吃饭"); }}Test classpublic
static.Example of an internal class accessing an external classclass Outer {int num =3;class inner{int num =4;void Show () {int num = 5; SYSTEM.OUT.PRINTLN (num);//5system.out.println (This.num);//4system.out.println (Inner.this.num);// 4system.out.println (Outer.this.num);//3}}}class innerclass{public static void Main (String [] args) {Outer.Inner in =new Outer
The so-called anonymous inner class is an inner class that has no name and is usually used only once for this type of inner class.An anonymous inner class must be declared as part of the new statement when it is created, and this will take another special form of the new sta
(string[] args){Player P2 = new player () {public void Play (){System.out.println ("playing basketball");}};P2.play ();}}② interfaceInterface IPlayer{public void play ();}public class Anonymousinnerclasstest{public static void Main (string[] args){IPlayer ip2 = new IPlayer () {public void Play (){System.out.println ("playing basketball");}};}}third, the application of the threadThere are two ways to implement threading: ① inherits the Thread
The similarities and differences between closures and anonymous internal classes.
As mentioned earlier, the maximum limit for anonymous inner classes is the ability to reference variables (their ability to reference variables): They can only reference class variables (class variables) and local final variables (locally
the anonymous inner class implements two ways of threading:The first way:
1. Inheriting the thread class
2. Overriding the Run method
3. Write the code that will be executed in the Run method
The second way:
1. How to pass a subclass object of runnable to thread
2. Overriding the Run method
3. Write the executed code in the
the anonymous inner class implements two ways of threading:The first way:
1. Inheriting the thread class
2. Overriding the Run method
3. Write the code that will be executed in the Run method
The second way:
1. How to pass a subclass object of runnable to thread
2. Overriding the Run method
3. Write the executed code in the
As we all know, there are more and more ways to parse XML, but there are four main approaches: DOM, SAX, Jdom, and dom4j
The following first gives the jar package download addresses for these four methods
DOM: It's all in the Java JDK now, in the Xml-apis.jar bag.
sax:http://sourceforge.net/projects/sax/
Jdom:http://jdom.org/downloads/index.html
dom4j:http://sourceforge.net/projects/dom4j/
Introduction and analysis of
1. What if someone asks you if the interface in Java can be new? I think the answer should be yes, when implementing an anonymous inner class.http://blog.csdn.net/cntanghai/article/details/60944812. If someone asks you if the class can be modified by private, I think the answer is yes, one of the benefits of the inner class
Four technologies that may challenge Java development advantages
Author: Bruce A. Tate; beyond Java (beyond Java) Author
Translator: lenovozhf
Copyright Disclaimer: Any website authorized by matrix.Be sureThe original source and author information of the article and this statement are displayed as hyperlink
(NewRunnable () {7 @Override8 Public voidrun () {9 Try {TenThread.Sleep (50); One}Catch(interruptedexception e) { A e.printstacktrace (); - } - for(inti = 0; I ) the System.out.println (str); - } - }). Start (); - +System.out.println ("Main thread finished"); - } +}① Line 4th defines a local variable str in the Main method, line 6th defines a local inner class thre
Can be used directly:map{Put ("test1", "test11");Put ("Test2", "test11");}}; To initialize.In the online search, this is the use of anonymous classes in the way to initialize. The first layer {} is the definition of an anonymous class, and the second layer {} is the definition of the initialization function.But what is not figured out is that this should be an in
of each line. Python open source, charging difficult advantages: no Java Popular
Cons: There is not much sense of existence in the language I think the disadvantage is:
1, Python is a bit slow, it seems cpython (official implementation) did not develop the JIT interpreter plan. Now there is a pypy project to do this thing, progress is good, worth looking forward to.
Of course, Python, it's really not impor
Basic Theory:
-----------------------------------------------------
Java internal class: the definition of an internal class is defined within another class.
The reason is:
1. An internal class object can access the implementation of the object created for it, includin
Ideal for small and medium sized projects
Various plug-ins to choose from
A simple and understandable document
You can change the configuration without restarting the server
Disadvantages:
It can be difficult to use the runtime language
Developing multithreaded applications, GORM may cause problems
Complex integration process
Delayed run time 5.Struts 2-java web Framework
The Apache struts is an open source, free MVC framework for developing modern
); System.out.println (Mc.getval ()); }}View CodePre-defined functional interfacesUsually we don't need to define the function interface ourselves, Java has provided some predefined functional interfaces.
Unaryoperator
Applies a unary operation to an object of type T and returns the result, with the method named apply.
Binaryoperator
Operates on two objects of type T and returns the result, with the method n
Java Collection frameworks such as set, map, and list do not provide any simple method for initialization. Each time a set is created, values must be added one by one. For example
CopyCode The Code is as follows: Set Letter. Add ('A ');
Letter. Add ('B ');
//...
Very tedious.
But use an anonymous internal class. It can be slightly simpler.
Copy code The Co
Basic theory:
-----------------------------------------------------
About Java Inner classes: an inner class is defined as a class that is defined within another class.
The reason for this exists is:
1. An object of an internal class can access the implementation of the obj
What are the main areas and what kind of scenarios are these advantages?
Reply content:Both sides can list many advantages, but the problem is too hasty ...
Here's a few words for Java:
The quality of the JVM is much better than Python's virtual machines. A high-quality python interpretation environment can be built in the JVM environment, not in the reverse.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.