警告:[未选中]未经检查的转换duaring编译

时间:2013-08-22 20:28:12

标签: java

我有这个午餐java线程的Java代码:

public void start(Stage primaryStage)
    {
        // TODO when Java 8 is released use this to set default Skin
        //setUserAgentStylesheet(STYLESHEET_CASPIAN);

        final Task<ObservableList<String>> friendTask = new Task()
        {
            @Override
            protected ObservableList<String> call() throws InterruptedException
            {
                ObservableList<String> foundFriends =
                        FXCollections.<String>observableArrayList();
                ObservableList<String> availableFriends =
                        FXCollections.observableArrayList("Network Module", "User Module", "User Interface", "User Controls");

                updateMessage("Loading Modules . . .");
                for (int i = 0; i < availableFriends.size(); i++)
                {
                    Thread.sleep(250);
                    updateProgress(i + 1, availableFriends.size());
                    String nextFriend = availableFriends.get(i);
                    foundFriends.add(nextFriend);
                    updateMessage("Loading Modules . . . Loading " + nextFriend);
                }

                updateMessage("All Modules are loaded.");
                Thread.sleep(1500);

                return foundFriends;
            }
        };

        showSplash(primaryStage, friendTask);
        new Thread(friendTask).start();
        initMainStage(primaryStage);
    }

我可以编译代码但是收到此警告消息:

Compiling 26 source files to /home/rcbandit/Desktop/test/DX-57DC/build/classes
/home/rcbandit/Desktop/test/DX-57DC/src/com/dx57dc/main/DX57DC.java:75: warning: [unchecked] unchecked conversion
        final Task<ObservableList<String>> friendTask = new Task()
  required: Task<ObservableList<String>>
  found:    <anonymous Task>
/home/rcbandit/Desktop/test/DX-57DC/src/com/dx57dc/main/DX57DC.java:139: warning: [unchecked] unchecked call to addListener(ChangeListener<? super T>) as a member of the raw type ObservableValue
        task.stateProperty().addListener(new ChangeListener<Worker.State>()
  where T is a type-variable:
    T extends Object declared in interface ObservableValue
2 warnings

你能告诉我如何解决这个问题吗?

P.S这是我得到第二个警告:

private void showSplash(final Stage mainStage, Task task)
    {

        final Stage splashStage = new Stage();
        progressText.textProperty().bind(task.messageProperty());
        loadProgress.progressProperty().bind(task.progressProperty());
        task.stateProperty().addListener(new ChangeListener<Worker.State>()
        {
            @Override
            public void changed(ObservableValue<? extends Worker.State> observableValue, Worker.State oldState, Worker.State newState)
            {
                if (newState == Worker.State.SUCCEEDED)
                {
                    loadProgress.progressProperty().unbind();
                    loadProgress.setProgress(1);
                    //mainStage.setIconified(false);
                    splashStage.toFront();
                    // Set splash screen fadeout effect
                    FadeTransition fadeSplash = new FadeTransition(Duration.seconds(0.4), splashLayout);
                    fadeSplash.setFromValue(1.0);
                    fadeSplash.setToValue(0.0);
                    fadeSplash.setOnFinished(new EventHandler<ActionEvent>()
                    {
                        @Override
                        public void handle(ActionEvent actionEvent)
                        {
                            splashStage.close();
                            mainStage.show();
                            mainStage.toFront();
                        }
                    });
                    fadeSplash.play();
                } // todo add code to gracefully handle other task states.
            }
        });
        Scene splashScene = new Scene(splashLayout);
        splashStage.initStyle(StageStyle.UNDECORATED);
        final Rectangle2D bounds = Screen.getPrimary().getBounds();
        splashStage.setScene(splashScene);
        splashStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SplashWidth / 2);
        splashStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SplashHeight / 2);
        splashStage.show();

        //StartPanel.initStartPage(mainStage);

    }

问题出在这一行:

task.stateProperty().addListener(new ChangeListener<Worker.State>()

我收到此错误消息:

Compiling 1 source file to /home/rcbandit/Desktop/test/DX-57DC/build/classes
/home/rcbandit/Desktop/test/DX-57DC/src/com/dx57dc/main/DX57DC.java:138: warning: [unchecked] unchecked call to addListener(ChangeListener<? super T>) as a member of the raw type ObservableValue
        task.stateProperty().addListener(new ChangeListener<Worker.State>()
  where T is a type-variable:
    T extends Object declared in interface ObservableValue
1 warning
compile:

1 个答案:

答案 0 :(得分:1)

如果您使用的是java7,请使用

Task<ObservableList<String>> friendTask = new Task<>()

或者你可以随时使用

Task<ObservableList<String>> friendTask = new Task<ObservableList<String>> ()