通达信 api 接口,接口的特点及注意事项
通达信 api 接口,接口常量用法
通达信 api 接口,接口的内容包括
通达信 api 接口,接口内容小结,重中之重
通达信 api 接口,接口的抽象方法与默认方法
通达信 api 接口,接口
public interface MyinterfaceAbstract {
//我们是抽象方法
public abstract void methed1();
abstract void methed2();
public void methed3();
void methed4();
//我是默认方法
public default void methed5() {
System.out.println('这是新添加的默认方法');
}
}
实现类一
public class MyinterfeceAbstractImpl implements MyinterfaceAbstract{
@Override
public void methed1() {
System.out.println('我是实现类一的第一个方法');
}
@Override
public void methed2() {
System.out.println('我是实现类一的第二个方法');
}
@Override
public void methed3() {
System.out.println('我是实现类一的第三个方法');
}
@Override
public void methed4() {
System.out.println('我是实现类一的第四个方法');
}
}
实现类二
public class MyinterfaceAbstratImpl2 implements MyinterfaceAbstract{
@Override
public void methed1() {
System.out.println('我是实现类二的第一个方法');
}
@Override
public void methed2() {
System.out.println('我是实现类二的第二个方法');
}
@Override
public void methed3() {
System.out.println('我是实现类二的第三个方法');
}
@Override
public void methed4() {
System.out.println('我是实现类二的第四个方法');
}
@Override
public void methed5() {
System.out.println('我覆盖重写了通达信 api 接口,接口的默认方法');
}
}
测试
public class Interface {
public static void main(String[] args) {
MyinterfeceAbstractImpl impl = new MyinterfeceAbstractImpl();
//我们执行的是抽象方法
impl.methed1();
impl.methed2();
impl.methed3();
impl.methed4();
//我执行的是默认方法,我的类中没有该方法,这个方法是从通达信 api 接口,接口中来的
impl.methed5();
MyinterfaceAbstratImpl2 impl2 = new MyinterfaceAbstratImpl2();
impl2.methed1();
impl2.methed2() ;
impl2.methed3() ;
impl2.methed4();
//我执行的是默认方法,但是我覆盖重写了通达信 api 接口,接口的默认方法
impl2.methed5();
}
}
同名方法,优先父类的方法,不会执行通达信 api 接口,接口的方法
通达信 api 接口,接口A
public interface MyinerfaceA {
//抽象方法
public abstract void methed1();
public abstract void methedAbs();
//默认方法
public default void metheddef(){
System.out.println('默认方法A');
}
}
通达信 api 接口,接口B
public interface MyinerfaceB {
public abstract void methed2();
public abstract void methedAbs();
public default void metheddef(){
System.out.println('默认方法B');
}
}
实现类
public class interdace implements MyinerfaceA,MyinerfaceB{
// 覆盖重写所有的抽象方法,重复名称的重写一次即可
@Override
public void methed1() {
System.out.println('覆盖重写了A方法');
}
@Override
public void methedAbs() {
System.out.println('覆盖重写了AB通达信 api 接口,接口都有的方法');
}
@Override
public void methed2() {
System.out.println('覆盖重写了B方法');
}
//共有的默认方法,必须重写
@Override
public void metheddef(){
System.out.println('重写AB共有的默认方法默认方法');
}
}
静态方法
通达信 api 接口,接口
public interface MyinterfaceStatic {
public static void methoed(){
System.out.println('这是一个静态方法');
}
}
实现类
public class MyinterfaceStaticImpl implements MyinterfaceStatic{
}
测试
public class ineterface {
public static void main(String[] args) {
MyinterfaceStaticImpl impl = new MyinterfaceStaticImpl();
// 错误写法
// impl.methed();
//正确写法,而且不用实例化对象
MyinterfaceStatic.methoed();
}
}
静态方法默认方法代码只差在default与static
通达信 api 接口,接口默认方法
public interface MyinterfacePrivate {
public default void methed1(){
System.out.println('默认方法一执行了');
methed3();
}
public default void methed2(){
System.out.println('默认方法二执行了');
methed3();
}
private void methed3(){
System.out.println('AAA');
System.out.println('BBB');
System.out.println('CCC');
}
}
实现类中无法调用privae
public class MyinterfacePrivateImpl implements MyinterfacePrivate{
}
文章为作者独立观点,不代表股票交易接口观点