如何将ant bootclasspath与-source 1.5 -target 1.5一起设置?
这怎么可能不是1.5 JDK的硬编码路径?我可以将环境变量设置为bootclasspath,类似于如何从ant使用JAVA_HOME吗?
理想情况下,我想做一些事情,例如设置环境变量或将参数传递给ant.
在Mac OS X 10.7.3上安装JDK7(Java 7)的链接是什么?
它安装的版本是什么?
它在我的盒子上安装在哪里?
我该如何使用它?
public class Test{
private String _canYouSeeMe = "yes";
<T extends Test> void genericMethod(T hey){
String s = hey._canYouSeeMe;
}
void method(Test hey){
String s = hey._canYouSeeMe;
}
}
Run Code Online (Sandbox Code Playgroud)
在针对JDK 1.6构建时,这种编译很好但是对于1.7,在genericMethod()中存在编译器错误:字段Test._canYouSeeMe不可见
可以通过使_canYouSeeMe受保护而不是私有来解决错误,但我只是想知道从1.6到1.7的变化
我已经搜索了很长一段时间,但所有结果都指向了Java 7之前的NIO解决方案.我已经使用NIO的东西从文件系统的特定位置读取文件,它比之前(Files.readAllBytes(path))更容易.现在,我想读取一个打包在WAR和类路径中的文件.我们目前使用类似于以下的代码执行此操作:
Input inputStream = this.getClass().getClassLoader().getResourceAsStream(fileName);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
/* iterate through the input stream to get all the bytes (no way to reliably find the size of the
* file behind the inputStream (see http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#available()))
*/
int byteInt = -1;
try
{
byteInt = inputStream.read();
while (byteInt != -1)
{
byteStream.write(byteInt);
byteInt = inputStream.read();
}
byteArray = byteStream.toByteArray();
inputStream.close();
return byteArray;
}
catch (IOException e)
{
//...
}
Run Code Online (Sandbox Code Playgroud)
虽然这很有效,但我希望有一个更容易/更好的方法来使用Java 7中的NIO.我猜我需要在类路径上获得一个表示此路径的Path对象,但我是不知道该怎么做.
如果这是一件非常容易的事,我道歉.我只是想不出来.谢谢您的帮助.
我下载android-studio-bundle-130.677228-windows并安装在我的电脑上.但是当我试图启动android工作室时,那里什么也没发生......它没有启动,没有错误.我也尝试以管理员身份运行它,但没有工作.那里的实际问题是什么?有人遇到过同样的问题吗?
在Java 7的try-with-resources构造中,我可以在语句中声明一个资源,当它超出范围时它将自动关闭.try
但是,我没有发现任何可用资源范围的迹象.具体来说,它是在try块的catch/ finally块中可用的吗?
我在Eclipse Kepler中尝试了以下内容,但它给人的印象是:
资源变量由内容辅助(代码完成)提供:

快速修复建议更改为资源变量,但这会递归地产生它尝试修复的相同问题:

在提出Eclipse Bug Tracker中的错误之前,我想知道正确的范围限制是什么.
我正在阅读有关JDK7中的try-with-resource的内容,当我考虑将我的应用程序升级为使用JDK7运行时,我遇到了这个问题.
当使用BufferedReader时,例如写入抛出IOException和close抛出IOException ..在catch块中我关注写入引发的IOException ..但我不会太在意关闭抛出的那个..
数据库连接和任何其他资源的问题相同..
作为一个例子,我创建了一个自动关闭资源:
public class AutoCloseableExample implements AutoCloseable {
public AutoCloseableExample() throws IOException{
throw new IOException();
}
@Override
public void close() throws IOException {
throw new IOException("An Exception During Close");
}
}
Run Code Online (Sandbox Code Playgroud)
现在使用它时:
public class AutoCloseTest {
public static void main(String[] args) throws Exception {
try (AutoCloseableExample example = new AutoCloseableExample()) {
System.out.println(example);
throw new IOException("An Exception During Read");
} catch (Exception x) {
System.out.println(x.getMessage());
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在不必为BufferedReader等类创建包装器的情况下区分这些异常?
大多数情况下,我将资源关闭在finally块中的try/catch中,而不关心处理它.
我有一个带有Java 1.7的CentOS 6虚拟机.
$ java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
$ javac -version
javac 1.7.0_51
Run Code Online (Sandbox Code Playgroud)
我需要使用Java 1.6而不是Java 1.7,所以我安装了它.
$ sudo yum install java-1.6.0-openjdk.x86_64
$ sudo yum install java-1.6.0-openjdk-devel.x86_64
Run Code Online (Sandbox Code Playgroud)
当我再次检查版本时,我会像以前一样.对于其他项目,我将需要Java 1.7,所以我想保留它.
现在我想配置我的虚拟机,以便默认的JDK 和默认的JRE都是1.6.我怎么做?另外,当我完成它后,如何切换回Java 1.7?
我建造了一些我不太懂的东西 - 我不知道它是如何工作的.我已经熟悉了这篇关于多篇解释的文章.
考虑这两个例外和代码:
public class MyException1 extends Exception {
// constructors, etc
String getCustomValue();
}
public class MyException2 extends Exception {
// constructors, etc
String getCustomValue() { return "foo"; }
}
try {
//...
} catch (MyException1|MyException2 e) {
e.getCustomValue(); // won't work, as I expected
}
Run Code Online (Sandbox Code Playgroud)
我将无法调用getCustomValue(),即使方法是相同的,因为在Java中,上面try/catch应该实际上是在转换MyException1/2为Exception(这就是我理解文档的方式).
但是,如果我引入这样的界面:
public interface CustomValueGetter {
String getCustomValue();
}
public class MyException1 extends Exception implements CustomValueGetter /*...*/
public class MyException2 extends Exception …Run Code Online (Sandbox Code Playgroud)