Java - confuse one rule for each file

One class for a file rule in Java confuses me a bit. I am writing an Android application and trying to implement the accepted answer to this question:

Generic class for AsyncTask in Android?

which requires an interface definition that implements class A, and class B takes its constructor as an argument.

So I need A.java and B.java, but where is the interface going? Does he need a separate java file? Should I define it inside A and B? If not, how to import it?

I will also have about 10 different AsyncTask classes, but I don’t want to worry about creating a new file for each of them. What would you suggest? Is there a way to put all 10 classes in one file? Or should I create a large if / then block inside the class and pass an argument telling which of the 10 different tasks I want to do?

+3
source share
2 answers

You have to put it in AsyncTaskCompleteListener.java. If it is in the same package, there is no need to import it. If in another package you can import it using the instructions import.

I suggest reading the java tutorial before moving on.

10+ - public static class . , - , - . , .

+2

? java?

. / , .

10 , .

? - , Java. , .

+2

Source: https://habr.com/ru/post/1782112/


All Articles