Author Topic: ArrayList should be List  (Read 4275 times)

uklance

  • Newbie
  • *
  • Posts: 7
    • View Profile
ArrayList should be List
« on: December 08, 2011, 11:23:54 AM »
I notice that a couple of the methods in the API require parameters of the concrete type java.util.ArrayList. It is generally good practice to require parameters of the interface (java.util.List) instead so that the implementation can be left to the developer. This is true for all collection types (including java.util.Map etc).

I suggest that you cahnge the following:

ZipFile.createZipFile(java.util.ArrayList sourceFileList,  ZipParameters parameters)
ZipFile.addFiles(java.util.ArrayList sourceFileList, ZipParameters parameters)

to:

ZipFile.createZipFile(java.util.List sourceFileList,  ZipParameters parameters)
ZipFile.addFiles(java.util.List sourceFileList, ZipParameters parameters)

Cheers,
Lance.

admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 403
    • View Profile
Re: ArrayList should be List
« Reply #1 on: December 14, 2011, 09:52:41 PM »
I completely agree with your proposal. I will change this in one of the upcoming releases (v1.2.7 is scheduled in a few days but unfortunately I cannot include this change in this release).

hubschrauber

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: ArrayList should be List
« Reply #2 on: November 24, 2012, 10:57:40 PM »
Sorry to resurrect this old thread, but I just grabbed the latest release (v1.3.1) and noticed this never got changed on ZipFile.addFiles(ArrayList sourceFileList, ZipParameters parameters), ZipFile.createZipFile(ArrayList sourceFileList, ZipParameters parameters), ZipFile.createZipFile(ArrayList sourceFileList, ZipParameters parameters, boolean splitArchive, long splitLength), etc. 

Considering that JDK versions lacking support for generics are generally obsolete at this point, you probably wouldn't offend too many people if you made the signature even more type-safe by also declaring the contained-type of the List variables/arguments, like ZipFile.addFiles(List<File> sourcefileList, ZipParameters parameters).

Also, although it doesn't matter as much as the public interfaces in the library, it would be an improvement in consistency to use interface types (instead of concrete class types) for local/private variables too.

e.g.

List<File> sourceFileList = new ArrayList<File>();

instead of

ArrayList sourceFileList = new ArrayList();

Henrypark

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • สมัคร gclub
Re: ArrayList should be List
« Reply #3 on: August 18, 2015, 02:17:30 PM »
I do not understand about the stories I want to ask you to help me.

 


Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 346

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 347

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 348

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 351

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 352

Warning: Cannot modify header information - headers already sent in /home/content/66/5374066/html/zip4j/forum/Sources/Errors.php on line 353
Connection Problems

Connection Problems

Sorry, SMF was unable to connect to the database. This may be caused by the server being busy. Please try again later.