2016-05-13 7 views
1

Ich habe meine eigene javafx.concurrent.Task umgesetzt, und ich will seine updateProgress Methode außerhalb ihrer Klassendeklaration aber Fehler nennen, sagt: Update (double, double) hat geschützten Zugang im TaskUpdate (double, double) Zugang im Task geschützt hat

Beispiel:

downloadTask.updateProgress(index,size); 

Ist das möglich?

+3

Warum würden Sie diese brauchen? Die Tatsache, dass es geschützt ist, bedeutet, dass die Designer dachten, dass es nur innerhalb der Aufgabe zugänglich sein sollte, was sinnvoll ist. Sie von außen anrufen zu wollen bedeutet, dass Sie etwas falsch machen. Wie auch immer, du kannst die Sichtbarkeit der Methode jederzeit erhöhen (http://stackoverflow.com/questions/12780779/why-java-allows-increasing-the-visibility-of-protected-methods-in-child-class) . – Itai

Antwort

0

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

-Code-Schnipsel aus 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; 
     } 
    } 
Verwandte Themen