Browse Source

202506050218

main
wangminjun 2 months ago
parent
commit
e81426312d
  1. 4
      w8/AI协助记录.txt
  2. 29
      w8/Fanxing.java
  3. 13
      w8/Fanxxingtest.java
  4. BIN
      w8/程序运行截图.png

4
w8/AI协助记录.txt

@ -0,0 +1,4 @@
1.利用AI复习泛型相关知识
2.查询的静态方法的相关知识,了解了静态方法是使用 static 关键字修饰的方法,它属于类本身 ,而不是类的实例
3.查询swap方法的使用场景,用于交换两个数据的位置或值
4.了解了静态方法的使用原则,如果方法不依赖于对象的状态,就使用静态方法

29
w8/Fanxing.java

@ -0,0 +1,29 @@
public class Fanxing<K, V> {
private K key;
private V value;
public Fanxing(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return key;
}
public V getValue() {
return value;
}
public void setKey(K key) {
this.key = key;
}
public void setValue(V value) {
this.value = value;
}
public static <K, V> Fanxing<V, K> swap(Fanxing<K, V> pair) {
return new Fanxing<>(pair.getValue(), pair.getKey());
}
}

13
w8/Fanxxingtest.java

@ -0,0 +1,13 @@
public class Fanxingtest {
public static void main(String[] args) {
Fanxing<Integer, String> fanxing = new Fanxing<>(888, "Fanxingtest");
System.out.println("原始Pair:");
System.out.println("Key: " + fanxing.getKey());
System.out.println("Value: " + fanxing.getValue());
Fanxing<String, Integer> swapped = Fanxing.swap(fanxing);
System.out.println("\n交换后的Pair:");
System.out.println("Key: " + swapped.getKey());
System.out.println("Value: " + swapped.getValue());
}
}

BIN
w8/程序运行截图.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

Loading…
Cancel
Save