我发现了越来越多关于Java 8的新闻 - 然而,Java 7刚刚被许多地方采用.例如,在我的工作中,我们仍然使用Java 6,即使我们中的一些人拥有Java 7.
我想知道 - Java可用版本的限制是什么?我们多久可以期望推出和实施新的Java规范.我一直认为Java 8将来会很遥远,因为Java 7仍在不断发展.
也许有一个很好的(非tl; dr)官方消息来源我缺少这些细节,如果有的话,请告诉我.
可能重复:
Lambda表达式在Java 8中不起作用?
简单,毫无意义的应用程序与lambda:
public static void main(String [] args){FileFilter java =(File f) - > f.getName().endsWith(".java"); }
将其设置为使用JDK 8.如果我不尝试使用lambda,则编译/运行正常.
但是,如果我这样做,我得到:
将源文件编译为...\JavaApplication1 \建立\类... JavaApplication1的\ src\javaapplication1\JavaApplication1.java:20:错误:lambda表达式没有在-source 1.8的FileFilter的Java =(文件F)的支持 - >˚F .getName()的endsWith.( "Java的."); (使用-source 8或更高版本来启用lambda表达式)1错误
似乎对它是源8还是源1.8感到困惑
现在使用lambda特定版本时工作,例如下面运行正常:
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
public class JavaApplication1 {
public static void main(String[] args) {
Arrays.asList(new File("c:/").listFiles((File f) -> f.getName().endsWith(".txt")))
.forEach( file-> {System.out.println(file);});
}
}
Run Code Online (Sandbox Code Playgroud) JavaFX NullPointerexception在将文本设置为文本字段时生成.此代码生成此异常:
public void invalidate() {
model.getLock().lock();
try {
memoryDisplayTextField.setText(model.getMemory() != 0 ? "M" : "");
mainDisplayTextField.setText(model.getDisplayText());
} finally {
model.getLock().unlock();
}
}
Run Code Online (Sandbox Code Playgroud)
Stacktrace如下:
java.lang.NullPointerException
at com.sun.javafx.text.TextLayout.layout(TextLayout.java:1365)
at com.sun.javafx.text.TextLayout.ensureLayout(TextLayout.java:174)
at com.sun.javafx.text.TextLayout.getBounds(TextLayout.java:197)
at javafx.scene.text.Text.getLogicalBounds(Text.java:387)
at javafx.scene.text.Text.impl_computeGeomBounds(Text.java:1182)
at javafx.scene.Node.updateGeomBounds(Node.java:3322)
at javafx.scene.Node.getGeomBounds(Node.java:3275)
at javafx.scene.Node.getLocalBounds(Node.java:3257)
at javafx.scene.Node.updateTxBounds(Node.java:3335)
at javafx.scene.Node.getTransformedBounds(Node.java:3175)
at javafx.scene.Node.updateBounds(Node.java:504)
at javafx.scene.Parent.updateBounds(Parent.java:1643)
at javafx.scene.Parent.updateBounds(Parent.java:1643)
at javafx.scene.Parent.updateBounds(Parent.java:1643)
at javafx.scene.Parent.updateBounds(Parent.java:1643)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2268)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:352)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:511)
at com.sun.javafx.tk.quantum.QuantumToolkit$12.run(QuantumToolkit.java:379)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
at com.sun.glass.ui.win.WinApplication$3$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
Run Code Online (Sandbox Code Playgroud)
有没有解决方法?或者我应该等到发布?
谢谢.
我可以覆盖功能接口的toString方法吗?或者改写.是否有优雅的方法来更改实现功能接口的匿名内部类并使用lambdas覆盖toString方法?我在JDK8中创建lamba表达式时可以覆盖toString.
interface Iface {
void do();
}
main() {
Iface iface = () -> /*do something*/
System.out.println(iface); // I would like to see anything useful in output
}
Run Code Online (Sandbox Code Playgroud)
我可以覆盖iface的toString吗?
java8-ea发行版并在Array.sort和之间进行了快速比较Arrays.parallelSort.这就是结果:

我可以理解,praralleSort至少应该像普通老式机器一样sort,如果不是更快......但事实并非如此.
惠普ProBook Intel Core i5与4G RAM上Ubuntu 13.04 Linux同版本的JDK:Java HotSpot(TM) 64-Bit Server VM (build 25.0-b23, mixed mode)
package com.cmd;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
for (int i=100; i <= 10_000_000; i*=10){
runTest(i);
}
}
private static void runTest(final int size){
// Fist obtain two Arrays of same data
Employee[] empArrForSort = createVeryLargeEmpArray(size);
Employee[] empArrForSortCopy = Arrays.copyOf(empArrForSort, …Run Code Online (Sandbox Code Playgroud) 我已阅读以下帖子
Oracle停止使用sun.reflect.Reflection.getCallerClass
我想知道这种变化究竟意味着什么.
1).意味着这个类sun.reflect.Reflection.getCallerClass会被重写以提供更多的安全性Java reflection吗?
2).意味着不再需要这门课程?也许另一种方法?
3).反思将在Java 8中结束.method.invoke将抛出UnsupportedOperationException.
4).这会影响与Spring或AspectJ面向方面编程相关的任何事情吗?
我很想知道因为我们使用Reflection method.invoke在发送到数据库之前为类提供了一些标志.如果反思是我可以用什么方法来提供我的行为,这就提出了另一个问题.我认为AOP是一种可行的方式.
非常感谢.
由于在下面的代码中,R扩展了Appendable,我不应该能够返回一个可以预期R的Appendable吗?
/**
* Produces an R, to which a T has been semantically appended,
* whatever that may mean for the given type.
*/
interface Appendable <R, T>
{
/**
* Append is not expected to modify this Appendable,
* but rather to return an R which is the result
* of the append.
*/
R append(T t);
}
interface PluralAppendable <R extends Appendable<R, T>, T>
extends Appendable<R, T>
{
default R append(T... els)
{
// Easier to debug than …Run Code Online (Sandbox Code Playgroud) 我可以这么说吗?
匿名类看起来像OO样式,而lambda表达式使它成为功能样式.
我知道如何使用final keywords.Suppose如果使一个类成为final,则它不能被继承,如果一个方法是final,那么它不能被覆盖,如果一个变量是final,那么该值不能被改变.但是我在这种情况下我有点困惑
final TextField urlTextField = new TextField();
Run Code Online (Sandbox Code Playgroud)
我认为如果urlTextField成为最终版,那么你就不能再做了
urlTextField = new textField().但在下面的示例中,为什么它是最终的
package org.carlfx;
import javafx.application.Application;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.concurrent.Worker.State;
import javafx.print.*;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.transform.Scale;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
/**
* Demo to use JavaFX 8 Printer API.
*
* @author cdea
*/
public class PrintDemo extends Application {
@Override
public void start(Stage primaryStage) {
final TextField urlTextField = new TextField(); …Run Code Online (Sandbox Code Playgroud) int x = 1;
Consumer<Object> f = (i) -> {
int x = 1; // invalid
};
Run Code Online (Sandbox Code Playgroud)
与
Consumer<Object> f = (i) -> {
int x = 1;
};
int x = 1; // valid
Run Code Online (Sandbox Code Playgroud)
想象一下方法中的那两个块.为什么第二个块有效?
java-8 ×10
java ×8
lambda ×2
closures ×1
covariance ×1
generics ×1
java-7 ×1
javafx ×1
netbeans-7 ×1
reflection ×1