我收到此错误
:/tmp$ javac DrawPowerSet.java
DrawPowerSet.java:38: error: incompatible types
String value = set.get(i);
^
required: String
found: Object
1 error
当我尝试编译这个小代码时:
我在ubuntu 15.10版上发表了
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/* @author Philippe Fournier-Viger, 2014 */
public class DrawPowerSet {
public static void main(String[] arg) throws IOException,
InterruptedException {
String[] set = new String[]{"a", "b", "c", "d", "e"};
String output = "input.dot";
BufferedWriter writer = new BufferedWriter(new FileWriter(output));
writer.write("digraph mygraph{");
for (long i = 0, max = 1 << set.length; i < max; i++) {
List newSet = new ArrayList();
for (int j = 0; j < set.length; j++) {
int isSet = (int) i & (1 << j);
if (isSet > 0) {
newSet.add(set[j]);
}
}
if (newSet.size() != set.length) {
printLinksToImmediateSupersets(newSet, set, writer);
}
}
writer.write("}");
writer.close();
}
private static void printLinksToImmediateSupersets(List subset,
String[] set, BufferedWriter writer) throws IOException {
for (int i = 0; i < set.length; i++) {
String value = set[i];
if (subset.contains(value) == false) {
List newSet = new ArrayList();
newSet.addAll(subset);
newSet.add(value);
writer.write(asString(subset) + " -> " + asString(newSet)
+ " \n");
}
}
}
private static String asString(List set) {
Collections.sort(set);
if (set.size() == 0) {
return "\"{}\"";
}
StringBuffer buffer = new StringBuffer();
buffer.append("\"{");
for (int i = 0; i < set.size(); i++) {
String value = set.get(i);
buffer.append(value);
if (i != set.size() - 1) {
buffer.append(",");
}
}
buffer.append("}\"");
return buffer.toString();
}
}
java -version