gpt4 book ai didi

Java 使用 -Xlint :unchecked for details 重新编译

转载 作者:太空宇宙 更新时间:2023-11-04 13:58:48 25 4
gpt4 key购买 nike

我有大量代码,但我收到了消息

Note: GenericSet.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

我真的不想发布所有代码,但如果你们能告诉我一种编译和查找错误的方法,那就太好了。我知道它必须处理泛型,我只是不知道如何找到代码中出现问题的位置。

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class GenericSet<T> implements ExtendedSet<T> {

private ArrayList<T> myList;

public GenericSet() {
myList = new ArrayList<T>(50);
}

public ArrayList<T> getList() {
return this.myList;

}


public void addThis(T item) {
this.myList.add(item);
}

public ExtendedSet<T> intersection(ExtendedSet<T> set) {
ArrayList<T> compareThis = ((GenericSet<T>)set).getList();
GenericSet<T> finalVal = new GenericSet();
for (T item : compareThis) {
if (this.myList.contains(item)) {
finalVal.addThis(item);
}
}
return finalVal;
}


public ExtendedSet<T> difference(ExtendedSet<T> set) {
ArrayList<T> compareThis = ((GenericSet<T>)set).getList();
GenericSet<T> finalVal = new GenericSet();
for (T item : compareThis) {
if (!(this.myList.contains(item))) {
finalVal.addThis(item);
}
}
return finalVal;
}

public ExtendedSet<T> union(ExtendedSet<T> set) {
ArrayList<T> base = this.getList();
ArrayList<T> compareThis = ((GenericSet<T>)set).getList();
GenericSet<T> finalVal = new GenericSet();
for (T item : compareThis) {
if (!(this.myList.contains(item))) {
finalVal.addThis(item);
}
}
for (T item: base) {
finalVal.addThis(item);
}
return finalVal;
}

public ExtendedSet<T> symmetricDifference(ExtendedSet<T> set) {
GenericSet<T> diffSet = new GenericSet();
ArrayList<T> compareThis = ((GenericSet<T>)set).getList();
ArrayList<T> base = this.getList();
for (T item : compareThis) {
if (!(this.myList.contains(item))) {
diffSet.addThis(item);
}
}
for (T item : base ) {
if (!(compareThis.contains(item))) {
diffSet.addThis(item);
}
}
return diffSet;
}

public ExtendedSet<ExtendedSet<T>> powerSet() {
GenericSet<ExtendedSet<T>> powerSet = new GenericSet();
for (int i = 0; i<(this.myList.size()); i++) {
GenericSet<T> newSet = new GenericSet();
for (int k = 0; k < i; k++) {
newSet.addThis(this.myList.get(k));
}
powerSet.addThis(newSet);
}
return powerSet;
}

public ExtendedSet<Tuple<T>> product(ExtendedSet<T> set) {
GenericSet<Tuple<T>> product = new GenericSet();
Object aList = this.myList.clone();
ArrayList<T> bList = ((GenericSet<T>)set).getList();
for (int i = 0; i < this.myList.size(); i++) {
GenericTuple addMe = new GenericTuple(((ArrayList<T>)aList).get(i), bList.get(i));
product.addThis(addMe);
}
return product;
}

public <E> ExtendedSet<E> map(LMap<T, E> map) {
GenericSet<E> finalVal = new GenericSet();
for (T item: this.myList) {
E ans = map.map(item);
finalVal.addThis(ans);
}
return finalVal;
}

public T reduce(LReduce<T> reduce) {
ArrayList<T> run = this.getList();
T end = run.get(0);
for (T item: this.myList) {
if (item != run.get(0)) {
end = reduce.reduce(end, item);
}
}
return end;
}

public ExtendedSet<T> filter(LFilter<T> filter) {
GenericSet<T> finalVal = new GenericSet();
for (T item: this.myList) {
if (filter.filter(item)) {
finalVal.addThis(item);
}
}
return finalVal;
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}

if (!(o instanceof GenericSet)) {
return false;
}

GenericSet<T> testMe = (GenericSet<T>) o;
boolean ans = true;
ArrayList<T> test = this.getList();
ArrayList<T> compare = testMe.getList();

for (int i = 0; i < test.size(); i++) {
if (test.get(i) != compare.get(i)) {
return false;
}
}
return true;
}

public void clear(){
this.myList.clear();
}

public boolean removeAll(Collection<?> c) {
boolean ans = this.myList.removeAll(c);
return ans;
}

public boolean retainAll(Collection<?> c) {
boolean ans = this.myList.retainAll(c);
return ans;
}

public boolean addAll(Collection<? extends T> c) {
boolean ans = this.myList.addAll(c);
return ans;
}

public boolean containsAll(Collection<?> c) {
boolean ans = this.myList.containsAll(c);
return ans;
}

public int size() {
int ans = this.myList.size();
return ans;
}

public boolean isEmpty() {
boolean ans = this.myList.isEmpty();
return ans;
}

public boolean contains(Object o) {
boolean ans = this.myList.contains(o);
return ans;
}

public Iterator<T> iterator() {
Iterator<T> ans = this.myList.iterator();
return ans;
}

public Object[] toArray() {
Object[] ans = this.myList.toArray();
return ans;
}

public <T> T[] toArray(T[] a) {
T[] ans = this.myList.toArray(a);
return ans;
}

public boolean add(T e) {
boolean ans = this.myList.add(e);
return ans;
}

public boolean remove(Object o) {
boolean ans = this.myList.remove(o);
return ans;
}

public int hashCode() {
int ans = this.myList.hashCode();
return ans;
}
}

最佳答案

您需要替换以下代码:

GenericSet<ExtendedSet<T>> powerSet = new GenericSet();

GenericSet<ExtendedSet<T>> powerSet = new GenericSet<ExtendedSet<T>>();

在你所有的声明中。如果您使用像 eclipse 这样的 IDE,带有警告的代码将以黄色下划线显示,以便于查找问题。

关于Java 使用 -Xlint :unchecked for details 重新编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29529678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com