Virtually all Java core classes that implement Comparable have natural orderings that are consistent with equals. In particular, such a sorted set (or sorted map) violates the general contract for set (or map), which is defined in terms of the equals method.įor example, if one adds two keys a and b such that (!a.equals(b) & a.compareTo(b) = 0) to a sorted set that does not use an explicit comparator, the second add operation returns false (and the size of the sorted set does not increase) because a and b are equivalent from the sorted set's perspective. This is so because sorted sets (and sorted maps) without explicit comparators behave "strangely" when they are used with elements (or keys) whose natural ordering is inconsistent with equals. It is strongly recommended (though not required) that natural orderings be consistent with equals. Note that null is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null) returns false. The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) = 0 has the same boolean value as e1.equals(e2) for every e1 and e2 of class C. Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator. Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort). This ordering is referred to as the class's This interface imposes a total ordering on the objects of each class that implements it. Type, XmlAccessOrder, XmlAccessType, XmlNsForm, Year, YearMonth, ZonedDateTime, ZoneOffset, ZoneOffsetTransition, ZoneOffsetTransitionRule. MessageType, TypeKind, URI, UUID, WebParam. State, Time, Timestamp, TimeUnit, TrayIcon. StateValue, TextStyle, ThaiBuddhistChronology, ThaiBuddhistDate, ThaiBuddhistEra, Thread. Status, StandardCopyOption, StandardLocation, StandardOpenOption, StandardProtocolFamily, String, SwingWorker. Use, SortOrder, SourceVersion, SSLEngineResult. Mode, Short, ShortBuffer, SignStyle, SOAPBinding. ComparisonType, RowIdLifetime, RowSorterEvent. AuthenticationType, RetentionPolicy, RoundingMode, RowFilter. Type, PseudoColumnUsage, Rdn, ResolverStyle, Resource. Option, PosixFilePermission, ProcessBuilder. Range, ObjectName, ObjectStreamField, OffsetDateTime, OffsetTime, PKIXReason, PKIXRevocationChecker. Scope, MinguoChronology, MinguoDate, MinguoEra, Modifier, Month, MonthDay, MultipleGradientPaint. FilteringMode, LocalTime, Long, LongBuffer, MappedByteBuffer, MemoryType, MessageContext. ComponentPlacement, LdapName, LinkOption, LocalDate, LocalDateTime, Locale. Alignment, HijrahChronology, HijrahDate, HijrahEra, Instant, IntBuffer, Integer, IsoChronology, IsoEra, JapaneseChronology, JapaneseDate, JavaFileObject. WindowTranslucency, GregorianCalendar, GroupLayout. Location, Double, DoubleBuffer, DropMode, Duration, ElementKind, ElementType, Enum, File, FileTime, FileVisitOption, FileVisitResult, Float, FloatBuffer, FormatStyle, Formatter. BaselineResizeBehavior, CompositeName, CompoundName, CRLReason, CryptoPrimitive, Date, Date, DayOfWeek, Desktop. UnicodeScript, CharBuffer, Charset, ChronoField, ChronoUnit, ClientInfoStatus, CollationKey, Collector. RequestorType, BigDecimal, BigInteger, Boolean, Byte, ByteBuffer, Calendar, CardTerminals. CacheMode, AccessMode, AclEntryFlag, AclEntryPermission, AclEntryType, AddressingFeature. Type Parameters: T - the type of objects that this object may be compared toĬhronoLocalDate, ChronoLocalDateTime, Chronology, ChronoZonedDateTime, Delayed, Name, Path, RunnableScheduledFuture, ScheduledFutureĪbstractChronology, AbstractRegionPainter.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |