2016-05-13 3 views
1
でのアクセスを保護していた

私は自分javafx.concurrent.Taskを実装している、と私はそのクラス宣言が、エラーの外にそのupdateProgressメソッドを呼び出すようにしたいと言う:タスクでのUpdateProgress(ダブル、ダブル)保護されたアクセスのUpdateProgress(ダブル、ダブル)は、タスク

例:

downloadTask.updateProgress(index,size); 

これは可能ですか?

+3

は、なぜあなたはこれを必要でしょうか?保護されているということは、設計者がタスク内からのみアクセスすべきだと思ったことを意味します。外部から電話したいのは、何か間違っている可能性があることを意味します。とにかく、いつでも[メソッドの可視性]を増やすことができます(http://stackoverflow.com/questions/12780779/why-java-allows-increasing-the-visibility-of-protected-methods-in-child-class) 。 – Itai

答えて

0

のJavadoc: https://docs.oracle.com/javafx/2/api/javafx/concurrent/Task.html

コードのjavadocからの抜粋:

public class IteratingTask extends Task<Integer> { 
     private final int totalIterations; 

     public IteratingTask(int totalIterations) { 
      this.totalIterations = totalIterations; 
     } 

     @Override protected Integer call() throws Exception { 
      int iterations = 0; 
      for (iterations = 0; iterations < totalIterations; iterations++) { 
       if (isCancelled()) { 
        updateMessage("Cancelled"); 
        break; 
       } 
       updateMessage("Iteration " + iterations); 
       updateProgress(iterations, totalIterations); 
      } 
      return iterations; 
     } 
    }