C++ typedef in Java?
C++ typedef in Java?
在Java中有类似于C++typedef/using的东西吗?用C++我会写
using LatLng = std::pair<double, double>;
Java中没有类型别名。
也没有类似decltype
的东西。
最接近decltype的事情可能是使用java中的泛型来处理的。
/**
* @author OldCurmudgeon
* @param <P> - The type of the first.
* @param <Q> - The type of the second.
*/
public class Pair<P extends Comparable<P>, Q extends Comparable<Q>> implements Comparable<Pair<P, Q>> {
// Exposing p & q directly for simplicity. They are final so this is safe.
public final P p;
public final Q q;
public Pair(P p, Q q) {
this.p = p;
this.q = q;
}
public P getP() {
return p;
}
public Q getQ() {
return q;
}
@Override
public String toString() {
return "<" + (p == null ? "" : p.toString()) + "," + (q == null ? "" : q.toString()) + ">";
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Pair)) {
return false;
}
Pair it = (Pair) o;
return p == null ? it.p == null : p.equals(it.p) && q == null ? it.q == null : q.equals(it.q);
}
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + (this.p != null ? this.p.hashCode() : 0);
hash = 97 * hash + (this.q != null ? this.q.hashCode() : 0);
return hash;
}
@Override
public int compareTo(Pair<P, Q> o) {
int diff = p == null ? (o.p == null ? 0 : -1) : p.compareTo(o.p);
if (diff == 0) {
diff = q == null ? (o.q == null ? 0 : -1) : q.compareTo(o.q);
}
return diff;
}
}
相关文章:
- Push_back and pop_back in java
- 线程中的异常 "main" java.lang.UnsatisfiedLinkError: no JNTIest in java.library.path
- implementing a patricia trie in java
- Java enum ordinal in JNI
- 您将如何为 std::list<std::string> 创建一个类型映射,以在<String> List in C++ 中为 Java 在 SWIG 中创建?
- Java varargs equivalent in C++
- C++ GUI in Java SWT
- Imgproc.convexityDefects(); In eclipse + java + opencv
- 从Bloch的Effective Java in C++实现类型安全的异构容器(VS2010)
- C++ typedef in Java?
- Wlan SSID in java/c++
- Decrypt CryptoAPI SIMPLEBLOB in Java
- Of C ++ in java (OpenCV)
- C++ vs Java in Android
- JNI, Java to C++ in Eclipse: undefined reference to '_imp__JNI_CreateJavaVM@12'
- Java HashSet equivalent in C++
- Tantamount of while(cin>>something){some task ;} in java?
- BufferedReader and InputStreamReader in Java
- Singleton in java vs. Singleton in C++
- Java hashmap.get() in c++