comparable Questions
13
Solved
I want to compare to variables, both of type T extends Number. Now I want to know which of the two variables is greater than the other or equal. Unfortunately I don't know the exact type yet, I onl...
Indebted asked 21/4, 2010 at 13:19
6
Solved
What is the standard way of making a class comparable in Python 3? (For example, by id.)
Menashem asked 2/8, 2011 at 4:40
5
Solved
Given two lists of different types, is it possible to make those types convertible between or comparable to each other (eg with a TypeConverter or similar) so that a LINQ query can compare them? I'...
Farleigh asked 3/4, 2012 at 17:43
4
Solved
I am just starting with Kotlin. I want to create a range from 1 to n where n is excluded. I found out that Kotlin has ranges and I can use them as follows:
1..n
But this is an inclusive range whic...
Dig asked 28/3, 2015 at 16:42
4
Solved
I have a distributed system defined by a sort of "state machine" ( "flow chart" )
each system writes there state in a shared "log"
I'm representing each state as part of a sealed trait and a give...
Sledge asked 3/9, 2019 at 14:48
1
Solved
In Go 1.18 and Go 1.19 I can ensure at compile time that a type is strictly comparable, i.e. it supports == and != operators and those are guaranteed to not panic at run time.
This is useful for ex...
Kiaochow asked 14/12, 2022 at 20:32
2
Solved
I have tried to use generics with Go, but I don't really understand when we use any or comparable as type parameter. Can someone help to understand these?
Headcheese asked 18/3, 2022 at 7:55
4
Solved
What I want to achieve is to get min/max attribute value of object from ArrayList<Object>. For example if Object has attribute weight(float), I want heaviest object from the list.
I've tried...
Infallible asked 23/9, 2018 at 12:43
1
Solved
In the code below, I define a generic linked list. Go1.18 is happy to use an instance of the list as a key to a map. However, the last line, when uncommented, doesn't compile; I get the error:
Con...
Paraldehyde asked 16/3, 2022 at 23:55
2
Solved
I know from official documentation that compareBy
creates a comparator using the sequence of functions to calculate a result of comparison. The functions are called sequentially, receive the given ...
Mas asked 10/3, 2022 at 7:9
4
Solved
How to make two objects in Java comparable using "<" or ">"
e.g.
MyObject<String> obj1= new MyObject<String>(“blablabla”, 25);
MyObject<String> obj2= new MyObject<String&g...
Multidisciplinary asked 21/3, 2015 at 4:18
4
Solved
I want to define a class that implements the generic Comparable interface. While in my class I also defined a generic type element T. In order to implement the interface, I delegate the comparison ...
Averroes asked 4/2, 2014 at 5:35
5
Solved
I need to find the smaller of two Comparable values:
Comparable<C> a = ...;
Comparable<C> b = ...;
Comparable<C> min = a.compareTo(b) <= 0 ? a : b;
This is similar to Math.min...
Pyrostat asked 10/7, 2018 at 13:0
3
Solved
I am playing around with Go Generics in the playground, trying to write some generic array functions.
https://gotipplay.golang.org/p/vS7f_Vxxy2j
package main
import (
"fmt"
)
func arra...
Thermistor asked 20/6, 2021 at 8:19
3
Solved
Given the following code :
public abstract class Participant {
private String fullName;
public Participant(String newFullName) {
this.fullName = new String(newFullName);
}
// some more cod...
Bullnose asked 1/1, 2012 at 18:59
7
Solved
I have a class for which equality (as per equals()) must be defined by the object identity, i.e. this == other.
I want to implement Comparable to order such objects (say by some getName() property...
Albritton asked 1/4, 2019 at 8:10
6
Solved
I'm a beginner in programming and I have two classes. First class is:
public class User implements Comparable<User>
with field int age, constructor and overrided method of interface Compar...
Cyd asked 17/3, 2017 at 17:31
4
Solved
I am able to compare Strings fine, but would like to know how I can rank floating point numbers?
getChange() returns a String. I want to be able to sort descending. How can I do this?
UPDATE:
pa...
Shebat asked 14/9, 2010 at 0:1
7
What is the difference between returning 0, returning 1 and returning -1 in compareTo() in Java?
Hercegovina asked 22/9, 2010 at 7:20
3
Solved
Say I have a class Foo(val a: String, val b: Int, val c: Date) and I want to sort a list of Foos based on all three properties. How would I go about this?
Nitz asked 10/11, 2015 at 22:27
7
Solved
I have a class
public class StudentVO {
int age;
String name;
}
I used the same class in two different areas. At one place i need to sort based on the age. In another place I need to sort bas...
Befoul asked 25/4, 2013 at 4:52
3
Solved
I don't understand the logic why List.sort() doesn't have a version with no comparator.
Specially I see it's possible to call List.sort with null:
list.sort(null), and it seems it uses the natural...
Motorist asked 15/4, 2020 at 6:13
4
Solved
I'm more or less Java programmer, so this might be a stupid question, but I didn't manage to find any simple solution.
I have a class like this in C++:
template<class T> class Node {...}
...
Gilkey asked 12/1, 2012 at 16:45
8
Solved
I have the following code where I am trying to put the StringBuffer objects as keys in a TreeSet. The reason I do this is to see if I can put mutable objects as keys. I do not get any compile error...
Characharabanc asked 22/8, 2013 at 19:33
2
Solved
I need to sort a List of items based on a List of Filters, which are ordered by priority. However, these Filters come from the API request body, so they can change.
I have a Filter class
public c...
Keister asked 11/6, 2019 at 0:56
1 Next >
© 2022 - 2025 — McMap. All rights reserved.