2023/11/7–C#–The difference between generics and Object types, generic constraints, ArrayList variable array, Dictionary dictionary class in C#….

1. Use of generics Generics is a programming concept that allows you to write code that can handle non-specific data types, thereby improving code reusability and type safety. Generics allow you to write common algorithms, data structures, and methods to adapt to a variety of different data types without having to write specific code for […]

rust generics and traits

Trait Define characteristics If different types have the same behavior, then we can define a trait and then implement that trait for those types. Defining characteristics is a combination of methods with the purpose of defining a set of behaviors necessary to achieve certain goals. For example, we now have two content carriers: Post and […]

golang gorm implements addition, deletion and modification of general single tables through generics

golang gorm implements general single table addition, deletion and modification through generics No nonsense, just jump into the code If you want to achieve universality, you must first implement universal query, which can be achieved by passing map func Where(where map[string]interface{}) func(db *gorm.DB) *gorm.DB { return func(db *gorm.DB) *gorm.DB { dbTmp := db for ko, […]

Typescript generics, keyof, typeof, index type, mapping

Typescript generics A major part of software engineering is building components that not only have well-defined and consistent APIs, but are also reusable. Components that can handle today’s and tomorrow’s data will give you the most flexible ability to build large software systems. Use generic type variables function identity<Type>(arg: Type): Type { return arg; } […]

Generics and Reflection in Java

Generics What are generics and what are their advantages The Java generics mechanism was only added in JDK1.5. Therefore, in order to be compatible with previous jdk versions, the implementation of Java generics adopts a “pseudo-generic” strategy, that is, Java supports generics in syntax, but will Perform “type erasure” and then the virtual machine will […]

Java Chapter Thirteen: Enumerated Types and Generics

Enumeration type Use enumeration types to set constants When setting constants, we usually place them in the interface so that they can be used directly in the program. This constant cannot be modified because when the constant is defined in the interface, the modifiers of the constant are changed to final and static. The general […]

Generics in Java: A powerful tool for efficient programming

Generics – A data type that accepts data types. Generics are a parameterized type mechanism in Java. Through type parameters, common code can be implemented in classes, interfaces and methods. Introduction of generics Generics are an important feature introduced in the Java programming language that allow programmers to write more versatile and safer code. In […]

GenericServlet, ServletConfig and ServletContext

2023.10.19 What are the disadvantages of writing a Servlet class to directly implement the Servlet interface? We only need the service method, other methods do not need to be used in most cases, and the code is very bloated. Solution: Write a GenericServlet class. This class is an abstract class with an abstract method service. […]

net core reflection obtains generics-generic method method<T>(T t1)

Refer to Microsoft instructions: How to: Examine and Instantiate Generic Types with Reflection – .NET Framework | Microsoft Learn target method public class GenericTest { public Dictionary<string, string> TestGeneric<T1, T2>(T1 t1, T2 t2) where T1 : TestBase, ITestArgument where T2 : class, new() { return null; } } //Judgment logic var testType = typeof(GenericTest); var […]

[C# Programming] Exception handling, generics

1. Exception handling 1.1 Multiple exception types C# allows code to throw derived from System.Exception. For example: public sealed class TextNumberParser { public static int Parse(string textDigit) { string[] digitTexts = { “zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine” }; int result = Array.IndexOf(digitTexts, textDigit.ToLower()); if(result < 0) throw new ArgumentException( “The […]