Giter VIP home page Giter VIP logo

java-template-classes's Introduction

Generic Classes


Generics, farklı referans veri tiplerini alan, hangi referans tipini alacağına karar verebileceğimiz ve üzerinde benzer işlemler yapabileceğimiz bir sınıfdır.
```
List list = new ArrayList();
list.add("Merhaba Dünya");
list.add(123);
for (int i = 0; i < list.size(); i++) {
    String string = (String) list.get(i);
}



     // Generic ifadeler kullanılarak
List<String> list = new ArrayList<String>();
list.add("Merhaba Dünya");
list.add(123);
for (int i = 0; i < list.size(); i++) {
    String string = list.get(i);
}

// Interface ile kullanım
public interface Comparable<T> {
    public int compareTo(T object);
}// Class ile kullanım
public class Printer<T> {
    public void print(T object) {
        System.out.println(object);
    }
}// Method ile kullanım -1
public <T> T myGenericMethod(){
    T object = null;
    //***
    return object;
}// Method ile kullanım -2
public <T> T myGenericMethodWithParameter(T object){
    return object;
}// Method ile kullanım -3
public <T> void myGenericVoidMethod(T object){
    System.out.println(object);
}

  • Genericler uygulamalarınızda ki hataları minimuma indirmeyi amaçlar. Özellikle Runtime sırasında oluşacak ClassCastException hatalarını derleme sırasında yakalayabiliriz.

  • Neden Generic tip tanımlarken T kullanılıyor? Neden X,Y,Z değil?

Generic ifadelerde dikkat etmişsinizdir hep T harifini kullandık. Bunun nedeni Java Naming Convention (Java İsimlendirme Standartları).
java-standart

java-template-classes's People

Contributors

isilsubasi08 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.