Should the addListener method check for duplicate registrations when called? If so, what should happen when a duplicate is found?
final public class exampleCanFire { public void addFooListener(FooListener listener) { // Before adding listener to private list of listeners, should I check for duplicates? } }
I prefer to store them in Listand not check for duplicates. Some advantages of this approach:
List
CopyOnWriteArrayList
ConcurrentModificationException
, . , , . , , .
- , IllegalArgumentException , .
IllegalArgumentException
, Set:
Set<FooListener> listeners = new HashSet<FooListener>(); public boolean addFooListener(FooListener listener) { return listeners.add(listener); }
, , JAVA. , JAVA - . , j_random_hacker , , , , , , ? -)
Source: https://habr.com/ru/post/1715876/More articles:How to use ConfigurationManager for DEBUG and RELEASE versions in VS 2008 projects - .netTFS - find all change shifts associated with a task - tfsJDBC Thin Oracle 11g - javaTFS: View general changes for all files in all changesets associated with a work item - version-controlprinting web browsers - c #How to count seeders and peers? - phpProgramming Resources for C ++ on Linux - c ++How to clear SQL session state for all users in ASP.NET - sql-serverудалить последние две строки char! - stringprogressBar, в то время как MainFrom инициализируется - c#All Articles