Examples of a real-life generic class

In a Java interview, I got the following question:

  • Could you name some common examples of classes from real life? Not from real life PROGRAMMING, but in general. For instance. You explain the pedigrees to someone who knows nothing about programming.

  • The same goes for the simplest design pattern - singleton.

I know of an idea about the first question (about generics), I tried to name various hand tools (for example, fretsaw) that work with only one type of material, but actually they are not generics.

Please avoid such collections of offers, it is too naive and obvious.

+5
source share
3 answers
  • , , , , . , . , , , . , - , , .

  • , , - - , , . , , .

+7

- .

Bowl<T> can be Bowl<Cookie> Bowl<Candy> ....
0

So, I want to buy a TV. I'm browsing List<TV>. But then I decided that I want to get an LCD TV. So, I instanceofthrough the list and receive List<LCD_TV>. Since I want to use the company tag, I call abstract TV.getManufacturer()and check if it is == company. Then I know that I need an LED LCD, so I call LCD_TV.getLcdType()and check if it is == LED. Then I just randomly selectlist.get( rand() % list.size() )

0
source

All Articles