1

I have implemented my own javafx.concurrent.Task, and I want to call its updateProgress method outside its class declaration but error says: updateProgress(double,double) has protected access in Task

Example:

downloadTask.updateProgress(index,size);

Is this possible?

Ethyl Casin
  • 791
  • 2
  • 16
  • 34
  • 3
    Why would you need this? The fact that it's protected means the designers thought it should only be accessed from within the task, which makes sense. Wanting to call it from outside means you may be doing something wrong. Anyway, you can always increase the [visibility of the method](http://stackoverflow.com/questions/12780779/why-java-allows-increasing-the-visibility-of-protected-methods-in-child-class). – Itai May 13 '16 at 09:58

1 Answers1

0

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

Code snippet from 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;
         }
     }
user1933888
  • 2,897
  • 3
  • 27
  • 36