I'm learning Java and would like to summarize one of the points (?) Interface that is easy to trip over.
An example of interface on Android is summarized in another article.
If you want to deepen your understanding of interface in Android application programming, I think it's a good idea to create your own listener.
How to write an interface.
Runnable in java.lang
is an example interface.
Runnable.java
package java.lang;
/**
* Represents a command that can be executed. Often used to run code in a
* different {@link Thread}.
*/
public interface Runnable {
/**
* Starts executing the active part of the class' code. This method is
* called when a thread is started that has been created with a class which
* implements {@code Runnable}.
*/
public void run();
}
To make it simple
Runnable.java
public interface Runnable {
public void run();
}
It will be like this.
A refreshing introduction to Java In the second edition, it is sometimes explained by the expression "abstract class in abstract class".
Contents of processing (without {/ * ... processing ... * /}
) Method.
Runnable.java
public void run();
Part of.
When you declare a field in the interface, it is treated as if you declared a constant in public static final
.
Abstract methods must be ** always overridden **, so when instantiating ʻinterface`,
python
Runnable runnable = new Runnable() {
@Override
public void run() {
}
};
In this way, you will create an instance while overriding the run ()
method.
--Introduction to Java that you can understand clearly 2nd edition -Interface Runnable
Recommended Posts