Questions
17 of 24
1What are the SOLID principles? Explain each briefly.
2Explain the Single Responsibility Principle (SRP) with an example.
3Explain the Open/Closed Principle (OCP). How do you achieve it without modifying existing code?
4Explain the Liskov Substitution Principle (LSP). What happens if it's violated? (Square/Rectangle problem)
5Explain the Interface Segregation Principle (ISP). Why are fat interfaces bad?
6Explain the Dependency Inversion Principle (DIP). How does it relate to Dependency Injection?
7What is the difference between Aggregation and Composition?
8What is the Factory Pattern? How does it help in achieving OCP?
9What is the Abstract Factory Pattern? How does it differ from Factory Method?
10What is the Strategy Pattern? How does it replace complex conditional logic?
11What is the Observer Pattern? Where is it used in real life? (Event handling, Pub/Sub)
12What is the Decorator Pattern? How does it add functionality dynamically?
13What is a Singleton Pattern? What are the thread-safety concerns and how to handle them?
14What is an Anti-Pattern? Can you name a few? (God Object, Spaghetti Code, Golden Hammer)
15What is "Coupling" and "Cohesion"? Explain the relationship between them.
16What are Generics/Templates? How do they improve type safety and performance compared to casting?
17What is Type Erasure (Java) vs Reified Generics (C#)?
18What is Variance in Generics? (Covariance and Contravariance)
19What are Extension Methods (C#) or Default Methods (Java)? When should you use them?
20What is Reflection? How can it be used to break Encapsulation? What are the performance costs?
21What is the "Law of Demeter"? (Don't talk to strangers)
22Explain "Tell, Don't Ask" principle.
23What is the DRY principle? How does OOP help achieve it?
24What is the YAGNI principle?
17 / 24

What is Type Erasure (Java) vs Reified Generics (C#)?

Difficulty: 5/10

Type Erasure vs Reified Generics

Java generics are primarily implemented using type erasure: generic type arguments are mostly removed from the runtime representation, with appropriate casts inserted by the compiler and bridge methods where necessary. Consequently, code generally cannot directly ask for the generic type argument at runtime, and Java cannot use primitive types such as int directly as generic type arguments. C# generics are reified: generic type information remains available at runtime, and the runtime can distinguish constructed generic types. C# also supports generic value types without boxing in many cases.

javascript
  1. 1

    Java generic type arguments are primarily erased at runtime.

  2. 2

    Java reflection can see generic metadata in some declarations, but that does not make generic arguments fully reified in ordinary runtime type checks.

  3. 3

    C# generic type arguments are reified at runtime.

  4. 4

    C# supports generic value types such as List without requiring the same boxing approach used by object-based collections.

  5. 5

    Type erasure helps Java maintain compatibility with much older bytecode and libraries.

  6. 6

    Reification enables richer runtime generic operations.

Follow-up Questions

  • Why did Java choose type erasure?
  • Can Java determine List versus List at runtime?
  • Why can C# use int as a generic type argument?
  • What is a raw type in Java?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.