5.10

来源:互联网 发布:电脑锣编程培训 编辑:程序博客网 时间:2024/06/10 06:27

JAVA     Override

标准注解——Deprecated       ——java.lang包

          SuppressWarnings

class Parent {

        publicfloat calculate(float a, float b) {

                return a*b;

        }

}

public class Child extends Parent {

        publicint calculate(int a, int b) {

                return (a+1)*b;

        }

}

通过Parent的子类Child 来扩展Parent并覆盖它的calculate方法

但是覆盖并没有成功,因为签名不同,子类返回并接受的是int而不是float


如果不能很清楚的看到父类中的内容

public class Child extends Parent{

        @Override

        public int calculate(int a, int b) {

                return (a+1)*b;

        }

}

这样编写,产生编译错误的时候,会明确的告知你Child中的calculate 方法没有覆盖父类中的方法


public class DeprecatedTest {

        @Deprecated

        public void serve() {             在DeprecatedTest类中弃用serve方法

        }

}


当用Deprecated来标识类或者接口时——弃用该类

@Deprecated

public class DeprecatedTest {

        public void serve() {

        }

}


@SuppressWarnings(value={string-1,....,string-n})

string-1到string-n表示要阻止的警告集合

有效参数

unchecked:给JAVA语言规范中规定的未检查的转换警告提供更为详细的信息

path:不存在的路径(类路径、源路径等)目录的警告

serial:可序列化的类缺少serialVersionUID定义的警告

finally:finally子句不能正常完成的警告

fallthrough:检测switch块的贯穿case


switch(i) {

case 1:

    System.out.println("1");

     break;

case 2:

    System.out.println("2");

     // falling through

case 3:

    System.out.println("3");

}


通用注解——>Generated——>标识相对于手写代码的计算机生成的源代码,适用于方法,类和域

value:代码生成器的名称

date:代码生成的日期,格式遵从ISO 8601

comments:与生成代码配套的注解


@Generated(value="com.brainysoftware.robot.CodeGenerator",

         date="2011-12-31",comments="Genrated code")

public class GeneratedTest {

}

         (注解)

标准元注解————>注解{Documented、Inherited、Retention、Target}————>java.lang.annotation包中

public class OverrideTest {

      @Override

      public String toString() {

        return "OverrideTest";

        }

}

使可以注解的注解在结果文档中可见


Retention——>SOURCE:要被java编译器丢掉的注解

            CLASS:要记录到类文件中但JVM不会保存的注解

            RUNTIME:JVM要保存的注解,可以用反射查询到

@Retention(value=SOURCE)

public @interface SuppressWarnings


Target

java.lang.annotation.ElimentType枚举的任一成员

@Target(value=METHOD)——>只适用于方法声明


@Target(value={TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE})——>SuppressWarnings


定制注解类型——>Java接口

public @interface CustomAnnotation {

}

@Documented

@Retention(RetentionPolicy.RUNTIME)

public @interface Author {

    String firstName();

    String lastName();

    boolean internalEmployee();

}


@Author(firstName="firstName", lastName="lastName",

        internalEmployee=true|false)

public calss Test {

}


通过反射查询注解——>java.lang.Class类中的与注解相关的方法

public <A extends java.lang.annotation.Annotation> A getAnnotation

      (Class<A> annotationClass)

如果存在,则返回这个元素指定注解类型的注解,否则返回null


public java.lang.annotation.Annotation[] getAnnotation()

返回这个类中出现的所有注解


public boolean isAnnotation()

如果这个类是一个注解类型,则返回true


public boolean isAnnotationPresent(Class<? extends

        java.lang.annotation.Annotation> annotationClass)

表示这个类是否有指定类型的注解



LINUX

iptables -F 清楚filter表中所有规则链中的规则,


添加规则到规则链表,允许源地址为192.168.78.1/24的主机通过22(ssh)端口

iptables -A INPUT -p tcp -s 192.168.78.1/24 --dport 22 -j ACCEPT


iptables 中 需要指定规则是要作用在哪一个规则表上,若不指定,就会默认作用在filter这个表上

该表包含三个链:INPUT     FORWARD     OUTPUT


iptables-save  ——> 保存IP表

显示IP表的内容

iptables-save(不带参数的情况下将显示filter表的内容)

显示IP表的内容,并且显示所有包和字节计数器当前的值

iptables-save -c

保存mangle表的内容到文件mangle.txt 中

iptables-save -t > mangle.txt


iptables-restore  ——>恢复IP表,通过标准输入上指定的数据来恢复IP表,也可以由shell提供的I/O重定向功能从一个文件中读取

从文件filter.txt 中恢复filter表

iptables-restore < filter.txt

iptables-save -t table


从文件mangle.txt中恢复mangle表,恢复所有包和字节计数器的当前值

iptables-restore -c < mangle.txt

iptables-save -c -t mangle


0 0
原创粉丝点击