Reflection – Getting the generic arguments from a System.Type instance

Use Type.GetGenericArguments. For example: using System; using System.Collections.Generic; public class Test { static void Main() { var dict = new Dictionary<string, int>(); Type type = dict.GetType(); Console.WriteLine(“Type arguments:”); foreach (Type arg in type.GetGenericArguments()) { Console.WriteLine(” {0}”, arg); } } } Output: Type arguments: System.String System.Int32

How to pass a type to generic method in Kotlin?

Here’s a complete example: import kotlin.reflect.KClass data class User(val name: String) data class Student(val name: String) fun getUsers(): List<User> = listOf(User(“JB”)) fun getStudents(): List<Student> = listOf(Student(“Claire”)) fun <T: Any> getData(clazz: KClass<T>): List<T>? { return when(clazz) { User::class -> getUsers() as List<T> Student::class -> getStudents() as List<T> else -> null } } fun main(args: Array<String>) { … Read more

What do constructor type arguments mean when placed *before* the type?

Calling a generic constructor This is unusual alright, but fully valid Java. To understand we need to know that a class may have a generic constructor, for example: public class TypeWithGenericConstructor { public <T> TypeWithGenericConstructor(T arg) { // TODO Auto-generated constructor stub } } I suppose that more often than not when instantiating the class … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)