201671010140. The sixth chapter of Java study 2016-2017-2 Java program

Source: Internet
Author: User
Tags comparable

Java Learning Chapter Sixth

This week we learned about interfaces in Java, lambda expressions, and inner classes, and here are some of the things I Learned:

1. Interface:

<1> All constants in the interface must be public static final, and the method must be public abstract, which is the default for the system, regardless of whether the write modifier is the same when you define the interface.

<2>. (1) An interface cannot construct an interface object, but it can declare an interface variable to point to a class object that implements the interface.
Comparable x = new comparable (...); ERROR
Comparable x= new Employee (...); Ok
(2) You can use instanceof to check whether an object implements an interface.
if (AnObject instanceof comparable)
{ ......}

2.lambda expression:

Lambda is a transitive code block that can be executed one or more times at a later time, and in some cases lambda expressions can simplify specific code, using lambda syntax instead of anonymous inner classes, making the code less and more readable.

Lambda expression Syntax:

Parameters, arrows (-a), and an expression.

3. Inner class:

In Java, a class can be defined inside another class or inside a method, and such a class is called an inner class. I think it's actually a nested class that defines a class in a class, where the inner class is the presenter, and the internal classes are free to use the method defined by the outer class, but the outer class wants to work with the inner class's method, and then it must first create an object of the member's inner class and then access it by referring to the object. A member inner class exists that is dependent on an external class, that is, if you want to create an object of the member's inner class, as long as an object of an outer class must exist.

In addition, in the completion of the experiment, there is a clue, can build the framework and algorithm, but not a clear idea to determine what each step to do, is I write a program of a major obstacle, I hope that in the accumulation, can be improved.

201671010140. The sixth chapter of Java study 2016-2017-2 Java program

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.