Approach
I wrote a benchmark program to evaluate different implementations:
instanceof
implementation (as reference)
- object-orientated via an abstract class and
@Override
a test method
- using an own type implementation
getClass() == _.class
implementation
I used jmh to run the benchmark with 100 warmup calls, 1000 iterations under measuring, and with 10 forks. So each option was measured with 10 000 times, which takes 12:18:57 to run the whole benchmark on my MacBook Pro with macOS 10.12.4 and Java 1.8. The benchmark measures the average time of each option. For more details see my implementation on GitHub.
For the sake of completeness: There is a previous version of this answer and my benchmark.
Results
| Operation | Runtime in nanoseconds per operation | Relative to instanceof |
|------------|--------------------------------------|------------------------|
| INSTANCEOF | 39,598 ± 0,022 ns/op | 100,00 % |
| GETCLASS | 39,687 ± 0,021 ns/op | 100,22 % |
| TYPE | 46,295 ± 0,026 ns/op | 116,91 % |
| OO | 48,078 ± 0,026 ns/op | 121,42 % |
tl;dr
In Java 1.8 instanceof
is the fastest approach, although getClass()
is very close.
A ListView is a specialized ListBox (that is, it inherits from ListBox). It allows you to specify different views rather than a straight list. You can either roll your own view, or use GridView (think explorer-like "details view"). It's basically the multi-column listbox, the cousin of windows form's listview.
If you don't need the additional capabilities of ListView, you can certainly use ListBox if you're simply showing a list of items (Even if the template is complex).
Best Answer
WPF Toolkit DataGrid should do 'Virtualization', which is what in Microsoft speak is 'reusing WPF objects' (see for example http://www.ytechie.com/2008/09/disabling-wpf-datagrid-virtualization.html).