我很想用jGraphT做这样的代码
/*
interface DirectedGraph<V,E> { ...}
interface WeightedGraph<V,E> { ...}
*/
public class SteinerTreeCalc {
public SteinerTreeCalc( < ??? implements DirectedGraph<V,E>, WeightedGraph<V,E> > graph ) {
......
}
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个构造函数,要求实现两个接口的对象.
更新:
在我的目标中,已经为Vertex和Edges(V和E)选择了类,但非常感谢那些想出的人:
public class SteinerTreeCalc <V, E, T extends DirectedGraph<V, E> & WeightedGraph<V, E>>
{
....
}
Run Code Online (Sandbox Code Playgroud) 我已经使用Java一年左右了,我不断发现自己用语言发现了新东西.有趣的是,大多数这些很酷的东西不是来自第三方API或库,而是来自JDK中提供的类.
所以我想知道,部分是出于好奇,部分出于对他人和我自己的教育,JDK中哪些课程最有趣/最有用/最喜欢?
我在我的页面中写了一个自定义链接,由views模块创建,我想点击它来做某事,然后页面将由ajax刷新,我该如何实现呢?
对不起,我没有清楚表达自己,我使用Drupal 7和Views模块来自定义我自己的页面.
在过去的几年里,我一直在研究一个支持.NET和SQL Server的团队.我很快就会加入一个Java和Oracle团队.我可以阅读/做什么来加快速度.
在java中是否有一个像这样的结构(这里用python实现):
[] = [item for item in oldList if item.getInt() > 5]
Run Code Online (Sandbox Code Playgroud)
今天我用的是:
ItemType newList = new ArrayList();
for( ItemType item : oldList ) {
if( item.getInt > 5) {
newList.add(item);
}
}
Run Code Online (Sandbox Code Playgroud)
对我而言,第一种方式看起来更聪明.
在Java的隐藏特性问题中,我对实例初始化器的答案感兴趣.
我想知道如何修改这一行:
List<Integer> numbers = new ArrayList<Integer>(){{ add(1); add(2); }};
Run Code Online (Sandbox Code Playgroud)
为了使它与嵌套的Arraylists执行相同的工作:
ArrayList<ArrayList<Integer>> numbers = ...
Run Code Online (Sandbox Code Playgroud)
那可能吗?
请考虑以下Java源代码:
if( agents != null ) {
for( Iterator iter = agents.keySet().iterator(); iter.hasNext(); ) {
// Code that uses iter.next() ...
//
}
}
Run Code Online (Sandbox Code Playgroud)
这agents是一个HashMap.
为什么for声明有时会抛出NullPointerException?
谢谢.
我感兴趣的是为什么这段代码产生语法错误,说明ImmutableMap无法解析为一个类型:
ImmutableMap<String, String> advice = ImmutableMap<String, String>.builder()
.put(KEY1, VAL1)
.put(KEY2, VAL2)
.build();
Run Code Online (Sandbox Code Playgroud)
虽然此代码按预期工作:
ImmutableMap<String, String> advice = ImmutableMap.<String, String>builder()
.put(KEY1, VAL1)
.put(KEY2, VAL2)
.build();
Run Code Online (Sandbox Code Playgroud)
这个时期不是我的心理模型应该去的地方,我希望有人可以解释为什么这个时期的"方法方面".我正在使用Guava的ImmutableMap,但它并不完全相关我不认为.我认为它与泛型有关,但我不确定是什么,我不知道如何寻找更好的答案,因为我不知道这个概念会被称为什么.
编辑:作为参考,ImmutableMap有这一行builder()
public static <K, V> Builder<K, V> builder() {
return new Builder<K, V>();
}
Run Code Online (Sandbox Code Playgroud) 这编译:
class Ex1 {
public int show() {
try {
int a=10/10;
return 10;
}
catch(ArithmeticException e) {
System.out.println(e);
}
finally {
System.out.println("Finally");
}
System.out.println("hello");
return 20;
}
}
Run Code Online (Sandbox Code Playgroud)
另一方面,这不是:
class Ex15 {
public int show() {
try {
int a=10/0;
return 10;
}
catch(ArithmeticException e) {
System.out.println(e);
}
finally {
System.out.println("Finally");
return 40;
}
System.out.println("hello");
return 20;
}
}
Run Code Online (Sandbox Code Playgroud)
并给出无法访问的语句System.out.println("hello"); 错误.为什么会这样?
finalize方法是使用受保护的作用域定义的,那么垃圾收集器等其他对象如何能够调用它.
我正在阅读Thinking in Java 4th Edition.描述了transient字段序列化的奇怪解决方法:
import java.io.*;
public class SerializationTest implements Serializable {
private String firstData;
//transient field, shouldn't be serialized.
transient private String secondData;
public SerializationTest(String firstData, String test2) {
this.firstData = firstData;
this.secondData = test2;
}
/**
* Private method, same signature as in Serializable interface
*
* @param stream
* @throws IOException
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
stream.writeObject(secondData);
}
/**
* Private method, same signature as in Serializable interface …Run Code Online (Sandbox Code Playgroud)