47、泛型

news2025/2/25 18:10:59

一、引入

1、传统方法:

package generic_;

import java.util.ArrayList;
@SuppressWarnings({"all"})
public class Generic01 {
    public static void main(String[] args) {
        ArrayList arrayList=new ArrayList();
        arrayList.add(new Dog("旺财",10));
        arrayList.add(new Dog("发财",1));
        arrayList.add(new Dog("招财",5));
        for(Object o:arrayList){
            Dog dog=(Dog)o;//向下转型
            System.out.println(dog.getName()+"-"+dog.getAge());
        }
        //旺财-10
        //发财-1
        //招财-5

        //如果不小心加入了一只猫,没有报错
        arrayList.add(new Cat("加菲猫",8));
    }
}
class Dog{
    private String name;
    private int age;
    public Dog(String name,int age){
        this.name=name;
        this.age=age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
class Cat{
    private String name;
    private int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

 2、使用泛型:

package generic_;

import java.util.ArrayList;
@SuppressWarnings({"all"})
public class Generic01 {
    public static void main(String[] args) {
        //解读:
        //1、ArrayList<Dog>表示存放到ArrayList集合中的元素是Dog类型
        //2、如果编译器发现添加的类型,不满足要求,就会报错
        //3、在遍历时,可以直接取出Dog类型,而不是Object
        ArrayList<Dog> arrayList=new ArrayList<Dog>();
        arrayList.add(new Dog("旺财",10));
        arrayList.add(new Dog("发财",1));
        arrayList.add(new Dog("招财",5));
        arrayList.add(new Cat("加菲猫",8));//报错
        for(Dog dog:arrayList){
            System.out.println(dog.getName()+"-"+dog.getAge());
        }
        //旺财-10
        //发财-1
        //招财-5
    }
}
class Dog{
    private String name;
    private int age;
    public Dog(String name,int age){
        this.name=name;
        this.age=age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
class Cat{
    private String name;
    private int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

3、 使用传统方法的问题分析:
(1)不能对加入到集合ArrayList中的数据类型进行约束(不安全)
(2)遍历的时候,需要进行类型转换,如果集合中的数据量较大,对效率有影响

4、泛型的好处
(1)编译时,检查添加元素的类型,提高了安全性
(2)减少了类型转换的次数,提高效率
 ·不使用泛型
Dog ->加入->object->取出->Dog//放入到Arraylist会先转成Object,在取出时,还需要转换成Dog
·使用泛型
Dog->Dog->Dog//放入时和取出时,不需要类型转换,提高效率
(3)不再提示编译警告

二、基本介绍:(“泛”:a whole group of things, not specific
1、老韩理解:泛型=>Integer,String,Dog,可以表示数据类型的一种类型
(1)泛型又称参数化类型,是Jdk5.0出现的新特性,解决数据类型的安全性问题
(2)在类声明或实例化时只要指定好需要的具体的类型即可
(3)Java泛型可以保证如果程序在编译时没有发出警告,运行时就不会产生ClassCastException异常。同时,代码更加简洁、健壮
(4)泛型的作用是:可以在类声明时通过一个标识表示类中某个属性的类型,或者是某个方法的返回值的类型,或者是参数类型。

package generic_;

public class Generic02 {
    public static void main(String[] args) {
        Person<String> person=new Person<String>("韩顺平教育");
        person.t();//class java.lang.String
        //此时class Person<E>{}里面的所有的E都用String替换

        Person<Integer> person1=new Person<Integer>(1);
        person1.t();//class java.lang.Integer
        //此时class Person<E>{}里面的所有的E都用Integer替换
    }
}
class Person<E>{
    E s;//E表示s的数据类型,该数据类型在定义Person对象时指定,即在编译期间,就确定E是什么类型

    public Person(E s) {//E也可以参数类型
        this.s = s;
    }
    public E f(){//返回类型使用E
        return s;
    }
    public void t(){
        System.out.println(s.getClass());//显示s的运行类型
    }
}

2、泛型的语法:

(1)泛型的声明:
interface接口<T>和class类<K{}
 //比如:List,ArrayList
说明:
1)其中,T,K,V不代表值,而是表示类型
2)任意字母都可以。常用T表示,是Type的缩写
(2)泛型的实例化:
要在类名后面指定类型参数的值(类型)。如:
1)List<String> strList= new ArrayList<String>0;

2) Iterator<Customer> iterator = customers.iterator0;

(3)

 //我的代码:

package generic_;

import java.util.*;

@SuppressWarnings({"all"})
public class TestGeneric2 {
    public static void main(String[] args) {
        Student student=new Student();
        Student student1=new Student();
        Student student2=new Student();

        HashSet hashSet=new HashSet();
        hashSet.add(student);
        hashSet.add(student1);
        hashSet.add(student2);

        HashMap hashMap = new HashMap();
        hashMap.put("jack",student);
        hashMap.put("tom",student1);
        hashMap.put("smith",student2);

        System.out.println("====================");
        Set keyset=hashMap.keySet();
        for (Object key :keyset) {
            System.out.println(key+"-"+hashMap.get(key));
        }

        System.out.println("====================");
        Set entrySet=hashMap.entrySet();
        for (Object entry:entrySet) {
            Map.Entry m=(Map.Entry)entry;
            System.out.println(m.getKey()+"-"+m.getValue());
        }


    }
}
class Student<E>{
    E student;
}
//====================
//tom-generic_.Student@4f3f5b24
//smith-generic_.Student@15aeb7ab
//jack-generic_.Student@27d6c5e0
//====================
//tom-generic_.Student@4f3f5b24
//smith-generic_.Student@15aeb7ab
//jack-generic_.Student@27d6c5e0

//老师的代码:

package generic_;
import java.util.*;

@SuppressWarnings({"all"})
public class TestGeneric2 {
    public static void main(String[] args) {
        HashSet<Student> students=new HashSet<Student>();
        students.add(new Student("jack",18));
        students.add(new Student("tom",28));
        students.add(new Student("mary",19));

        for (Student student :students) {
            System.out.println(student);
        }

        HashMap<String, Student> hm = new HashMap<String, Student>();
        hm.put("tom",new Student("tom",28));
        hm.put("smith",new Student("smith",48));
        hm.put("hsp",new Student("hsp",28));

        //迭代器
        /*自动填充的原因(hm.entrySet().var):
            public Set<Map.Entry<K,V>> entrySet(){
                Set<Map.Entry<K,V>> es;
                return (es=entrySet)==null?(entrySet=new EntrySet()):es;
            }
         */
        Set<Map.Entry<String, Student>> entries = hm.entrySet();

        /*自动填充的原因(entries.iterator().var):
            public final Iterator<Map.Entry<K,V>> iterator(){
                return new EntryIterator();
            }
         */
        Iterator<Map.Entry<String, Student>> iterator = entries.iterator();
        System.out.println("===========================");
        while (iterator.hasNext()) {
            Map.Entry<String,Student> next=iterator.next();
            System.out.println(next.getKey()+"-"+next.getValue());
        }
    }
}
//Student{name='mary', age=19}
//Student{name='jack', age=18}
//Student{name='tom', age=28}
//===========================
//tom-Student{name='tom', age=28}
//smith-Student{name='smith', age=48}
//hsp-Student{name='hsp', age=28}
class Student{
    private String name;
    private int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

3、泛型使用的注意事项和细节:
(1)interface List<T>{},public class HashSet<E>{}.等等
说明:T,E只能是引用类型,不能是基本数据类型
看看下面语句是否正确?:
List<Integer> list = new ArrayList<lnteger>();//对
List<int> list2 = new ArrayList<int>();//错

(2)在指定泛型具体类型后,可以传入该类型或者其子类类型
(3)泛型使用形式
List<Integer> list1 = new Arraylist<Integer>();
List<Integer> list2 = new ArrayList<>()://推荐,因为编译器会自动进行类型推断
(4)如果我们这样写List  list3=new  ArrayList();默认给它的泛型是[<E>E就是Object]

4、课堂练习题

 //我的代码:

package generic_;

import java.util.ArrayList;
import java.util.Comparator;

@SuppressWarnings({"all"})
public class GenericExercise01 {
    public static void main(String[] args) {
        ArrayList<Employee> arrayList=new ArrayList<Employee>();
        Employee jack = new Employee("jack", 10000, new MyDate(2000, 1, 1));
        Employee tom = new Employee("tom", 20000, new MyDate(2001, 1, 1));
        Employee smith = new Employee("smith", 30000, new MyDate(2002, 1, 1));
        arrayList.add(jack);
        arrayList.add(tom);
        arrayList.add(smith);
        arrayList.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                if(o1.getName().equals(o2.getName())){
                    if(o1.getBirthday()==o2.getBirthday()){

                    }else if(o1.getBirthday().getYear()==o2.getBirthday().getYear()){
                        if(o1.getBirthday().getMonth()==o2.getBirthday().getMonth()){
                            if(o1.getBirthday().getDay()==o2.getBirthday().getDay()){
                                return 0;
                            }else{
                                return o1.getBirthday().getDay()-o2.getBirthday().getDay();
                            }
                        }else{
                            return o1.getBirthday().getMonth()-o2.getBirthday().getMonth();
                        }
                    }else{
                        return o1.getBirthday().getYear()-o1.getBirthday().getYear();
                    }
                }else{
                    return o1.getName().length()-o2.getName().length();
                }
                return 0;
            }
        });
        System.out.println(arrayList);
        //[Employee{name='tom', sal=20000.0, birthday=MyDate{year=2001, month=1, day=1}}, Employee{name='jack', sal=10000.0, birthday=MyDate{year=2000, month=1, day=1}}, Employee{name='smith', sal=30000.0, birthday=MyDate{year=2002, month=1, day=1}}]
    }
}
class Employee{
    private String name;
    private double sal;
    private MyDate birthday;

    public Employee(String name, double sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthday=" + birthday +
                '}';
    }
}
class MyDate{
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
}

//老师的代码:

package generic_;

import java.util.ArrayList;
import java.util.Comparator;

@SuppressWarnings({"all"})
public class GenericExercise01 {
    public static void main(String[] args) {
        ArrayList<Employee> employees=new ArrayList<Employee>();
        employees.add(new Employee("jack", 10000, new MyDate(2000, 1, 1)));
        employees.add(new Employee("tom", 20000, new MyDate(2001, 1, 1)));
        employees.add(new Employee("smith", 30000, new MyDate(2002, 1, 1)));

        System.out.println("employees="+employees);
        employees.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                //验证传入的参数
                if(!(o1 instanceof Employee&&o2 instanceof Employee)){
                    System.out.println("类型不正确");
                    return 0;
                }
                //比较name
                int i=o1.getName().compareTo(o2.getName());
                if (i != 0) {
                    return i;
                }
                return o1.getBirthday().compareTo(o2.getBirthday());
            }
        });
        System.out.println("=========排序后=========");
        System.out.println("employees="+employees);
       }
}
//employees=[
//Employee{name='jack', sal=10000.0, birthday=MyDate{year=2000, month=1, day=1}}, 
//Employee{name='tom', sal=20000.0, birthday=MyDate{year=2001, month=1, day=1}}, 
//Employee{name='smith', sal=30000.0, birthday=MyDate{year=2002, month=1, day=1}}]
//=========排序后=========
//employees=[
//Employee{name='jack', sal=10000.0, birthday=MyDate{year=2000, month=1, day=1}}, 
//Employee{name='smith', sal=30000.0, birthday=MyDate{year=2002, month=1, day=1}}, 
//Employee{name='tom', sal=20000.0, birthday=MyDate{year=2001, month=1, day=1}}]
class Employee{
    private String name;
    private double sal;
    private MyDate birthday;

    public Employee(String name, double sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return '\n'+"Employee{" +
                "name='" + name + '\'' +
                ", sal=" + sal +
                ", birthday=" + birthday +
                '}';
    }
}
class MyDate{
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }
    //把对year-month-day的比较封装到MyDate类里面
    public int compareTo(MyDate o){
        //比较birthday的year
        int yearMinus=year-o.getYear();
        if (yearMinus != 0) {
            return yearMinus;
        }
        //比较birthday的month
        int monthMinus=month-o.getMonth();
        if (monthMinus != 0) {
            return monthMinus;
        }
        //比较birthday的day
        return day-o.getDay();
    }
}

5、自定义泛型(1)基本语法:

class类名<TR...>{//可以有多个泛型
 成员

}

(2)注意细节:
1)普通成员可以使用泛型(属性、方法)
2)使用泛型的数组,不能初始化
3)静态方法中不能使用类的泛型
4)泛型类的类型,是在创建对象时确定的(因为创建对象时,需要指定确定类型)

5)如果在创建对象时,没有指定类型,默认为Object

package generic_;

import java.util.ArrayList;
@SuppressWarnings({"all"})
public class CustomMethodGeneric {
    public static void main(String[] args) {
        Car car = new Car();
        car.fly("宝马",100);//当调用方法时,传入参数,编译器就会确定类型
        //class java.lang.String
        //class java.lang.Integer
        System.out.println("========================");
        car.fly(300,100.1);//当调用方法时,传入参数,编译器就会确定类型
        //class java.lang.Integer
        //class java.lang.Double

        System.out.println("========================");
        Fish<String, ArrayList> fish = new Fish<>();
        fish.hello(new ArrayList(),11.3f);
        //class java.util.ArrayList
        //class java.lang.Float
    }
}
class Car{//普通类
    public void run(){

    }

    //1、<T,R>就是泛型
    //2、是提供给fly使用的,不是返回类型
    public <T,R> void fly(T t,R r){//泛型方法
        System.out.println(t.getClass());//自动装箱,String / Integer / Double...
        System.out.println(r.getClass());//自动装箱,String / Integer / Double...
    }
}
class Fish<T,R>{//泛型类
    public void run(){

    }
    public <U,M> void eat(U u,M m){//泛型方法

    }

    //1、hi()方法不是泛型方法
    //2、是hi()方法使用了类声明的泛型
    //3、泛型方法 和 方法使用泛型 是不一样的
    public void hi(T t){

    }

    //泛型方法,可以使用类声明的泛型,也可以使用自己声明泛型
    public <K> void hello(R r,K k){//(R r,K k)中的R来自类的声明处,K来自方法的定义处
        System.out.println(r.getClass());
        System.out.println(k.getClass());
    }
}

6、泛型的继承和通配符:
(1)泛型不具备继承性
List<Object> list= new  ArrayList<String>()://对吗?
(2)<?>:支持任意泛型类型
(3)<?extends A>:支持A类以及A类的子类,规定了泛型的上限
(4)<?super A>:支持A类以及A类的父类,不限于直接父类,规定了泛型的下限

package generic_;

import java.util.ArrayList;
import java.util.List;

public class GenericExtends {
    public static void main(String[] args) {
        List<Object> list1=new ArrayList<>();
        List<String> list2=new ArrayList<>();
        List<A> list3=new ArrayList<>();
        List<B> list4=new ArrayList<>();
        List<C> list5=new ArrayList<>();

        //List<?>
        printCollection1(list1);
        printCollection1(list2);
        printCollection1(list3);
        printCollection1(list4);
        printCollection1(list5);

        //List<? extends A>
        printCollection2(list1);//报错
        printCollection2(list2);//报错
        printCollection2(list3);
        printCollection2(list4);
        printCollection2(list5);

        //List<? super A>
        printCollection3(list1);
        printCollection3(list2);//报错
        printCollection3(list3);
        printCollection3(list4);//报错
        printCollection3(list5);//报错
    }

    //方法一:
    //List<?>表示任意的泛型类型都可以接受
    public static void printCollection1(List<?> c){
        for(Object object:c){//通配符,取出时,就是Object
            System.out.println(object);
        }
    }

    //方法二:
    //<? extends A>:规定了泛型的上限,可以接受A或A子类
    public static void printCollection2(List<? extends A> c){
        for(Object object:c){
            System.out.println(object);
        }
    }

    //方法三:
    //<? super A>子类类名A:支持A类以及A类的父类,不限于直接父类,规定了泛型的下限
    public static void printCollection3(List<? super A> c){
        for(Object object:c){
            System.out.println(object);
        }
    }
}
class A{

}
class B extends A{

}
class C extends B{

}

7、

 //我的代码:

package generic_;

import java.util.List;
import java.util.Map;
import java.util.Set;

@SuppressWarnings({"all"})
public class Homework01 {
    public static void main(String[] args) {
        User jack = new User(1, 18, "jack");
        User tom = new User(2, 19, "tom");
        User smith = new User(3, 20, "smith");
        

    }
}
class DAO<T>{
    Map <String,T> stu;

    public DAO(Map<String, T> stu) {
        this.stu = stu;
    }

    public void save(String id, T entity){
        System.out.println(stu.put(id,entity));
    }
    public T get(String id){
        return stu.get(id);
    }
    public void update(String id,T entity){
        System.out.println(stu.replace(id,entity));
    }
    public List <T> list(){
        Set keySet=stu.keySet();
        List list=null;
        int size=stu.size();
        for(int i=0;i<size;i++){
            list.add(stu.get(keySet));
        }
        return list;
    }
    public void delete(String id){
        System.out.println(stu.remove(id));
    }
}
class User{
    private int id;
    private int age;
    private String name;

    public User(int id, int age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}

//老师的代码:

package generic_;

import innerclass.D;
import org.junit.Test;

import java.util.List;
import java.util.Map;
import java.util.Set;

@SuppressWarnings({"all"})
public class Homework01 {
    public static void main(String[] args) {
        User jack = new User(1, 18, "jack");
        User tom = new User(2, 19, "tom");
        User smith = new User(3, 20, "smith");


    }
    @Test
    public void testList(){
        DAO<User> dao=new DAO<>();
        dao.save("001",new User(1,10,"jack"));
        dao.save("002",new User(2,18,"king"));
        dao.save("003",new User(3,38,"smith"));

        List<User> list=dao.list();
        System.out.println("list="+list);

        System.out.println("==============================");
        dao.update("003",new User(3,58,"milan"));
        dao.delete("001");
        list=dao.list();
        System.out.println("list="+list);

        System.out.println("==============================");
        System.out.println("id==003:"+dao.get("003"));
    }
}
//list=[User{id=1, age=10, name='jack'}, User{id=2, age=18, name='king'}, User{id=3, age=38, name='smith'}]
//==============================
//list=[User{id=2, age=18, name='king'}, User{id=3, age=58, name='milan'}]
//==============================
//id==003 User{id=3, age=58, name='milan'}
package generic_;

import java.util.*;

public class DAO<T>{
    private Map<String,T> map=new HashMap<>();//搞清楚怎么定义这个成员变量的

    public void save(String id, T entity){
        map.put(id,entity);
    }
    public T get(String id){
        return map.get(id);
    }
    public void update(String id,T entity){
        map.put(id,entity);
    }

    //遍历map[k-v],将map的所有value(T entity),封装到ArrayList返回即可
    public List<T> list(){
        List<T> list = new ArrayList<>();
        Set<String> keySet=map.keySet();
        for (String key:keySet) {
            list.add(map.get(key));
        }
        return list;
    }
    public void delete(String id){
        map.remove(id);
    }
}
package generic_;

public class User{
    private int id;
    private int age;
    private String name;

    public User(int id, int age, String name) {
        this.id = id;
        this.age = age;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
}

三、JUnit

1、为什么需要JUnit?

(1) 一个类有很多功能代码需要测试,为了测试,就需要写入到main方法中
(2) 如果有多个功能代码测试,就需要来回注销,切换很麻烦
(3)如果可以直接运行一个方法,就方便很多,并且可以给出相关信息,就好了

2、基本介绍:
(1)JUnit是一个Java语言的单元测试框架
(2)多数Java的开发环境都已经集成了JUnit作为单元测试的工具

3、操作:

(1)在要测试的方法上面写“@Test

 2、快捷键alt+enter,“Add 'JUnit5.4' to classpath”,选最新的就行了

 3、下次用时就可以自动导入了,点击“小绿箭”就可以运行了

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/39595.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Spring项目结合Maven【实现读取不同的资源环境】

&#x1f4c3;目录跳转&#x1f4da;简介&#xff1a;&#x1f351;修改pom.xml&#x1f95e;修改application.yml&#x1f680; 演示&#xff1a;&#x1f4da;简介&#xff1a; 由于我们写功能的不能影响到线上环境的配置&#xff0c;所以每一次增加功能我们都要吧项目部署到…

STM32HAL库单ADC+DMA学习及测试记录

一、打开STM32CubeMX选择对应的芯片型号&#xff0c;后进入开发界面 1、双击“STM32CubeMX”软件打开&#xff0c;打开后如下图所示&#xff0c;选择红色框&#xff1b; 选择后可能会更新&#xff0c;等待更新完成即可&#xff0c;如下图&#xff1a; 2、选择开发芯片&#x…

【剧前爆米花--爪哇岛寻宝】面向对象的三大特性——封装、继承以及多态的详细剖析(上——继承)。

作者&#xff1a;困了电视剧 专栏&#xff1a;《JavaSE语法与底层详解》 文章分布&#xff1a;这是一篇关于Java面向对象三大特性——继承的文章&#xff0c;在本篇文章中我会分享继承的一些基础语法以及类在继承时代码的底层逻辑和执行顺序。 目录 继承 需求 继承的定义及语…

nginx(六十八)proxy模块(八)nginx与上游的ssl握手

一 nginx作为客户端与上游的SSL/TLS握手 理解上&#xff1a; nginx作为客户端,此时类似浏览器的角色,发请求建立连接 nginx作为server端与下游进行SSL/TLS握手 ① nginx与后端选择什么样的协议 1&#xff09;如果nginx与上游是局域网内,一般通过http建立请求,不需要进行…

详解__int128,最大可用整数类型

前言&#xff1a;有些题目需要的数值刚好比 long long 的最大值大那么一点点&#xff0c;那么我们就可以用__int128 来搏一搏&#xff08;并不是所有OJ都支持这个数据类型&#xff0c;受编译标准影响&#xff09; 最大值是多少 int 最大值&#xff1a;2^(32-1)-1【受电脑字长影…

碳中和专题:碳足迹核算、碳中和顶刊论文、碳排放交易2022

&#xff08;1&#xff09;碳中和顶刊论文 1、数据来源&#xff1a;自身 2、具体内容&#xff1a; 01周宏春&#xff1a;碳循环经济内涵、实践及其碳中和的深远影响.pdf 02谢和平&#xff1a;碳中和目标下煤炭行业发展机遇.pdf 03秦阿宁&#xff1a;碳中和背景下的国际绿色技…

【FPGA】基于状态机实现自动售货机模拟

文章目录一、售货机功能二、售货机状态分析及模块划分三、代码实现四、上板验证一、售货机功能 此自动售货机模拟基于EP4CE6F17C8开发板实现&#xff0c;用按键&#xff0c;led灯&#xff0c;数码管表示各个输入输出 功能&#xff1a; 此自动售货机可以选择A&#xff08;三元…

[激光原理与应用-21]:《激光原理与技术》-7- 激光技术大汇总与总体概述

目录 前言&#xff1a; 第1章 什么是激光技术 1.1 什么是激光技术 1.2 激光技术的分类方法 第2章 激光的应用技术 2.1 激光加工技术 2.2 激光快速成型 2.3 激光切割 2.4 激光焊接 2.5 激光雕刻 2.6 激光打孔 2.7 激光蚀刻 2.8 激光手术 2.9 激光武器 2.10 激光能…

详解诊断数据库ODX-D

文章目录 前言一、ODX-D具体内容是什么?二、ODX企标中关于ODX-D定义内容三、ODX-D在CANdelaStudio以及ODXStudio中定义内容总结前言 ​又是一周末,静下心码下字,将ODX这个Topic补充完整。 ODX含义是开放式诊断数据交互,是欧洲那边提出诊断数据架构,详情可如下图: 核心…

区间信息维护与查询【树状数组 】 - 原理2 多维树状数组

区间信息维护与查询【树状数组 】 - 原理2 多维树状数组 我们已经知道一维树状数组修改和查询的时间复杂度均为O (logn)&#xff0c;可以扩展为m 维树状数组&#xff0c;其时间复杂度为O (log ^m n )&#xff0c;对该算法只需加上一层循环即可。二维数组a [n ][n ]、树状数组c…

创建TCP通信与粘包问题解决

创建TCP通信 nodeJS的Net模块实现了底层通信接口 通信过程 创建服务端&#xff1a;接收和回写客户端数据创建客户端&#xff1a;发送和接收服务端数据数据传输&#xff1a; 内置服务事件和方法读写数据 通信事件 listing事件&#xff1a;调用server.listen方法之后触发con…

介绍 10 个有用的 Flutter 软件包

介绍 10 个有用的 Flutter 软件包 原文 https://genotechies.medium.com/introducing-10-useful-flutter-packages-1252c4b75fa7 前言 FLutter 软件包使您的开发简单快速。然而&#xff0c;有利有弊。有时候&#xff0c;如果从头开始开发这个特性将是有益的&#xff0c;因为可定…

Hive日分区表如何快速导入到StarRocks

1、背景 业务现状&#xff1a;集团使用FineBI做数据呈现及报表分析工具&#xff0c;经过近两年的BI建设&#xff0c;供应链域及营销域的BI建设已初具规模并体系化。数仓规模60TB&#xff0c;FineBI数据集约8000个&#xff0c;BI挂出报表数约1600个&#xff0c;报表月增幅在40左…

非凡社群管理之社群管理有什么内容

社群作为一个非常重要的私域流量池&#xff0c;它本身就是一个提升用户价值的利器。但如果管理不好社群&#xff0c;那么也是无济于事的。 社群小助手提示&#xff1a;高效管理社群&#xff0c;以下这五个方面要做好。 一&#xff0c;社群为用户解决问题&#xff0c;让群成员都…

iwebsec靶场 SQL注入漏洞通关笔记6- 宽字节注入

系列文章目录 iwebsec靶场 SQL注入漏洞通关笔记1- 数字型注入_mooyuan的博客-CSDN博客 iwebsec靶场 SQL注入漏洞通关笔记2- 字符型注入&#xff08;宽字节注入&#xff09;_mooyuan的博客-CSDN博客 iwebsec靶场 SQL注入漏洞通关笔记3- bool注入&#xff08;布尔型盲注&#…

【ML特征工程】第 7 章 :通过K-Means 模型堆叠进行非线性特征化

&#x1f50e;大家好&#xff0c;我是Sonhhxg_柒&#xff0c;希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流&#x1f50e; &#x1f4dd;个人主页&#xff0d;Sonhhxg_柒的博客_CSDN博客 &#x1f4c3; &#x1f381;欢迎各位→点赞…

计算机视觉之目标检测(object detection)《1》

在计算机视觉领域&#xff0c;除了识别图像并分类之外&#xff0c;我们很多时候想关注图像里面一些感兴趣的目标&#xff0c;比如视频监控中寻找一个或多个嫌疑犯&#xff1b;无人驾驶需要识别车辆、行人、红绿灯、路障等等&#xff0c;都是需要去及时掌握画面中的不同目标。我…

古瑞瓦特能源通过聆讯:上半年营收23亿 IDG投资9亿持股6.5%

雷递网 雷建平 11月26日古瑞瓦特能源&#xff08;简称&#xff1a;“Growatt Technology”&#xff09;日前递交招股书&#xff0c;准备在香港上市。上半年营收23.45亿古瑞瓦特能源于2011年在深圳成立&#xff0c;是一家分布式能源解决方案提供商&#xff0c;专注于可持续能源发…

Crack:GoJS 2.2.18 -2022-09-08 update

使用 JavaScript 和 TypeScript 为 Web 构建图表 流程图 构建交互式流程图或流程图。让您的用户使用 JSON 模型输出构建、修改和保存图表。状态图 可视化状态图和其他行为图。创建具有实时更新的图表以监控状态&#xff0c;或创建交互式图表以进行规划。桑基图 GoJS 允许对链接…

史上最全MATLAB误差分析工具箱,不看别后悔 【矢量化代码、效率嘎嘎快、支持计算50种指标】

在拟合、插值、模拟预测等计算中&#xff0c;往往需要通过不同指标参数来分析实际值与计算值之间差异依次衡量相关方法的可行性。常用的表征指标有残差平方和(SSE)、均方差(MSE)、均方根差(RMSE)、平均绝对误差(MAE)和决定系数R方(R-Squared)等等。 考虑到误差分析在实际应用中…