JAVA使用sealed,non-sealed对继承进行限制和var推断类型的应用------JAVA

package com.example.demo;

import com.example.Pk2.Line;
import com.example.Pk2.Rectangle;
import com.example.Pk2.Shape;
import org.junit.Test;

public class SwitchTest {
    @Test
    public void Test01(){
        int week = 6;
//        计算结果
        String memo = "";
        switch (week){
            case 1 -> memo = "休息日";
            case 2,3,4,5,6 -> memo = "工作日";
            case 7 -> memo = "星期六";
            default -> throw new RuntimeException("无效的日期");
        }
        System.out.println(memo);
    }
    @Test
    public void Test02(){
        int week = 60;
//        计算结果
        String memo = switch (week){
            case 1 : yield "休息日";
            case 2,3,4,5,6 : yield "工作日";
            case 7 : yield "星期六";
            default : yield "无效的日期";
        };
        System.out.println(memo);
    }
    @Test
    public void Test03(){
        int week = 1;
        String memo = switch (week){
            case 1 -> {
                System.out.println("星期日");
                yield "星期日";
            }
            case 2,3,4,5,6 -> {
                System.out.println("工作日");
                yield "工作日";
            }
            case 7 -> {
                System.out.println("星期六");
                yield "星期六";
            }
            default -> {
                System.out.println("非法日期");
                yield "非法日期";
            }
        };
        System.out.println("memo是"+memo);
    }

    @Test
    public void Test04(){
        Line line = new Line(10, 20);
        Rectangle rectangle = new Rectangle(20, 50);
        Shape shape = new Shape(50, 80);
        Object obj = shape;
        int result = switch (obj){
            case Line(int x,int y) -> {
//                可以在代码块操作我们的Record的值,非常方便
                System.out.println("Line");
                yield x + y;
            }
            //                可以在代码块操作我们的Record的值,非常方便
            case Rectangle(int w,int h) -> 2 * (2 + h);
            //                可以在代码块操作我们的Record的值,非常方便
            case Shape(int x,int y) -> {
                System.out.println("Shape");
                yield x * y;
            }
            default -> {
                System.out.println("啥也不是,散会");
                yield 0;
            }
        };
        System.out.println(result);
    }

    @Test
    public void Test(){
        String s = """
                Jack
                Rose
                select * from employees
                """;
        System.out.println(s);
    }
    @Test
    public void Test05(){
//        加了空格也会自动trim掉,仍然结果为true
        String s = """
                lisi     
                """;
        String s1 = """
                lisi
                """;
        System.out.println(s.equals(s1));
        System.out.println(s == s1);
        String msg = """
                Hello World
                """;
        System.out.println(msg.substring(0, 5));
    }
    @Test
    public void Test06(){
//        需要按Tab来后推,用空格键会被trim掉
//        tab才能保留缩进效果
        String html = """
                <html>
                    <body>哈哈哈哈</body>
                </html>
                """;
        System.out.println(html);
    }
    @Test
    public void Test07(){
        String colors = """
                red
                green
                blue
                """;
//        加五个空格
        colors = colors.indent(5);
        System.out.println(colors);
    }
    @Test
    public void Test08(){
        String info = """
                Name:%s,
                Phone:%s,
                Age:%d
                """.formatted("Jack","15919996103",20);
//        formatted方法可以为文本块中的内容赋值
        System.out.println(info);
    }
    @Test
    public void Test09(){
//        \表示换行符,避免了一行文字过长且实现了可读性的增强
        String info = """
                Spring Boot是一个快速开发框架\
                是\"Spring\"家族的一个成员\
                创建Spring项目
                """;
        System.out.println(info);
    }

    @Test
    public void varTest(){
        var s1 = "Hello";
        var i = 10;
    }


}
package com.example.demo;

import com.example.Pk2.Line;
import com.example.Pk2.Rectangle;
import com.example.Pk2.Shape;
import org.junit.Test;

public class SwitchTest {
    @Test
    public void Test01(){
        int week = 6;
//        计算结果
        String memo = "";
        switch (week){
            case 1 -> memo = "休息日";
            case 2,3,4,5,6 -> memo = "工作日";
            case 7 -> memo = "星期六";
            default -> throw new RuntimeException("无效的日期");
        }
        System.out.println(memo);
    }
    @Test
    public void Test02(){
        int week = 60;
//        计算结果
        String memo = switch (week){
            case 1 : yield "休息日";
            case 2,3,4,5,6 : yield "工作日";
            case 7 : yield "星期六";
            default : yield "无效的日期";
        };
        System.out.println(memo);
    }
    @Test
    public void Test03(){
        int week = 1;
        String memo = switch (week){
            case 1 -> {
                System.out.println("星期日");
                yield "星期日";
            }
            case 2,3,4,5,6 -> {
                System.out.println("工作日");
                yield "工作日";
            }
            case 7 -> {
                System.out.println("星期六");
                yield "星期六";
            }
            default -> {
                System.out.println("非法日期");
                yield "非法日期";
            }
        };
        System.out.println("memo是"+memo);
    }

    @Test
    public void Test04(){
        Line line = new Line(10, 20);
        Rectangle rectangle = new Rectangle(20, 50);
        Shape shape = new Shape(50, 80);
        Object obj = shape;
        int result = switch (obj){
            case Line(int x,int y) -> {
//                可以在代码块操作我们的Record的值,非常方便
                System.out.println("Line");
                yield x + y;
            }
            //                可以在代码块操作我们的Record的值,非常方便
            case Rectangle(int w,int h) -> 2 * (2 + h);
            //                可以在代码块操作我们的Record的值,非常方便
            case Shape(int x,int y) -> {
                System.out.println("Shape");
                yield x * y;
            }
            default -> {
                System.out.println("啥也不是,散会");
                yield 0;
            }
        };
        System.out.println(result);
    }

    @Test
    public void Test(){
        String s = """
                Jack
                Rose
                select * from employees
                """;
        System.out.println(s);
    }
    @Test
    public void Test05(){
//        加了空格也会自动trim掉,仍然结果为true
        String s = """
                lisi     
                """;
        String s1 = """
                lisi
                """;
        System.out.println(s.equals(s1));
        System.out.println(s == s1);
        String msg = """
                Hello World
                """;
        System.out.println(msg.substring(0, 5));
    }
    @Test
    public void Test06(){
//        需要按Tab来后推,用空格键会被trim掉
//        tab才能保留缩进效果
        String html = """
                <html>
                    <body>哈哈哈哈</body>
                </html>
                """;
        System.out.println(html);
    }
    @Test
    public void Test07(){
        String colors = """
                red
                green
                blue
                """;
//        加五个空格
        colors = colors.indent(5);
        System.out.println(colors);
    }
    @Test
    public void Test08(){
        String info = """
                Name:%s,
                Phone:%s,
                Age:%d
                """.formatted("Jack","15919996103",20);
//        formatted方法可以为文本块中的内容赋值
        System.out.println(info);
    }
    @Test
    public void Test09(){
//        \表示换行符,避免了一行文字过长且实现了可读性的增强
        String info = """
                Spring Boot是一个快速开发框架\
                是\"Spring\"家族的一个成员\
                创建Spring项目
                """;
        System.out.println(info);
    }

    @Test
    public void varTest(){
        var s1 = "Hello";
        var i = 10;
    }


}
package com.example.Pk3;

//密闭类只有指定的可继承
public sealed class Shape permits Circle,Square,Rectangle{
    private Integer width;
    private Integer height;
    public void draw(){
        System.out.println(width);
        System.out.println(height);
        System.out.println(this.getClass().getName());
    }
}
package com.example.Pk3;

//密闭类只有指定的可继承
public sealed class Shape permits Circle,Square,Rectangle{
    private Integer width;
    private Integer height;
    public void draw(){
        System.out.println(width);
        System.out.println(height);
        System.out.println(this.getClass().getName());
    }
}
package com.example.Pk3;

//放弃密闭,可以任意继承
public non-sealed class Rectangle extends Shape{
    @Override
    public void draw() {
        System.out.println("Rectangle");
    }
}
package com.example.Pk3;

//放弃密闭,可以任意继承
public non-sealed class Rectangle extends Shape{
    @Override
    public void draw() {
        System.out.println("Rectangle");
    }
}
package com.example.Pk3;

//仍是密闭类,可以指定继承者
public sealed class Square extends Shape permits RoundSquare{
    @Override
    public void draw() {
        System.out.println("Square");
    }
}
package com.example.Pk3;

//仍是密闭类,可以指定继承者
public sealed class Square extends Shape permits RoundSquare{
    @Override
    public void draw() {
        System.out.println("Square");
    }
}
package com.example.Pk3;

//final修饰的都不可在继承
public final class RoundSquare extends Square {
    @Override
    public void draw() {
        System.out.println("RoundSquare");
    }
}
package com.example.Pk3;

//final修饰的都不可在继承
public final class RoundSquare extends Square {
    @Override
    public void draw() {
        System.out.println("RoundSquare");
    }
}
package com.example.Pk3;

//final修饰的都不可在继承
public final class Circle extends Shape{
    @Override
    public void draw() {
        System.out.println("Circle");
    }
}
package com.example.Pk3;

//final修饰的都不可在继承
public final class Circle extends Shape{
    @Override
    public void draw() {
        System.out.println("Circle");
    }
}
  • 21
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
MIL-HDBK-217F, Notice 1 is issued to correct minor typographical errors in the basic F Revision. MIL HDBK-217F(base document) provides the following changes based upon recently completed studies (see Ret 30 and 32 listed in Appendix C) 1. New failure rate prediction models are provided for the following nine major classes of microcircuits Monolithic Bipolar Digital and Linear Gate/Logic Array Devices Monolithic MOS Digital and Linear Gate/Logic Array Devices Monolithic Bipolar and MOS Digital Microprocessor Devices(Including Controllers Monolithic Bipolar and Mos Memory Devices Monolithic GaAs Digital Devices Monolithic GaAs MMIC Devices Hybrid Microcircuits Magnetic Bubble Memories Surface Acoustic Wave Devices This revision provides new prediction models for bipolar and Mos microcircuits with gate counts up to 60,000, linear microcircuits with up to 3000 transistors, bipolar and Mos digital microprocessor and co- processors up to 32 bits, memory devices with up to 1 million bits, GaAs monolithic microwave integrated circuits(MMICs)with up to 1,000 active elements, and GaAs digital ICs with up to 10,000 transistors. The C, factors have been extensively revised to reflect new technology devices with improved reliability, and the activation energies representing the temperature sensitivity of the dice(IT)have been changed for MOS devices and for memories. The Ca factor remains unchanged from the previous Handbook version, but includes pin grid arrays and surlace mount packages using the same model as hermetic, solder-sealed dual in-line packages. New values have been included for the quality factor (o), the learning factor(i, and the environmental factor(aE). The model for hybrid microcircuits has been revised to be simpler to use, to delete the temperature dependence of the seal and interconnect fallure rate contributions, and to provide a method of calculating chip junction temperatures 2. A new model for Very High Speed Integrated Circuits(VHSIC/HSIC Like)and very Large Scale Integration(VLSi)devices (gate counts above 60, 000 3. The reformatting of the entire handbook to make i easier to use. 4. A reduction in the number of environmental factors( F)from 27 to 14 5. A revised fallure rate model for Network Resistors 6. Revised models for TWTs and Klystrons based on data supplied by the Electronic Industries Association Microwave Tube Division Supersedes page vil of Revision F A1emn彐TTu"“11r4raeK

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旧约Alatus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值