Snapdragon 665 vs Snapdragon 675 Which is Better

Ravi     2020-07-02 10:33:27    


Snapdragon 665 vs Snapdragon 675 Which is Better

The title might sound like a  B-rated horror movie, but in reality, Kotlin’s “reified” keyword helps you do things that were not possible before. Generics provide type safety and help you avoid explicit type casts. Generics extend the type system to allow a type or method to operate on objects of various types while providing compile-time type safety. On the other hand, generics can be limiting when you need to access type info in a generic function, and the compiler tells you the info doesn’t exist!

This missing type info is a result of how generics are implemented in the JVM (hint: type erasure, which we’ll discuss later). As a workaround, you can access the deleted generic type by passing the class of the generic type as a parameter of the function.

This isn’t too bad, but as you know from other posts in the Kotlin Vocabulary series, Kotlin hates boilerplate code and aims to help you write less code! Kotlin addresses this problem with a unique keyword, reified, that lets you access the type info from within a generic function. If you are familiar with how generics work, you might be asking how this is even possible. 

Generics

Before generics were added to Java with version 5.0, type info didn’t exist in collections. This means there is no indication if an Array-list is an Array-list of String, Integer, or any other object type.

Without generics, each time you want to access an object in a collection you need to perform an explicit cast. Plus, there is no guard against invalid casts which result in runtime exceptions.

To address this, generics were added in Java 5. With generics, you can define a specific type for a collection, and the compiler will warn you if you try to add any other type. Also, you don’t need to perform explicit casts, which might result in runtime exceptions.