www.fatihkabakci.com

Personal Website and Computer Science TUR EN

JAVA GENERICS BOUNDED TYPES

Last update: 10/3/2014 6:28:00 PM

Yazan:Fatih KABAKCI

Jenerikler java programlarında tasarlanan algoritmaların tek düze veri tiplerine mahkum olmasını engellemektedir.Jenerikleri kullanarak sınırsız sayıda farklı türden nesneler ile çalışabilirsiniz.Ancak bazen sadece belirli bir grup veri türleriyle çalışmak algoritmanın yapısına daha uygundur.Örneğin üçgenin çevresini hesaplayan bir program yazacağımızı düşünelim.Bu durumda jenerikler olsa da olmasa da çalışılacak veri türleri sayısal(numerik) veriler olacaktır.Java da ise Short,Integer,Long,Float ve Double matematiksel dört işlemler için kullanılan sınıflardır.Bu sınıfların her biri ise java.lang.Number sınıfından türetilmiştir. Yani String gibi bir nesne bizim işimize yaramayacaktır.

Bounded types,oluşturulacak olan jenerik yapılarının altındaki algoritmanın doğasına göre,belirli bir şablon altında sınırlandırılan nesnelere denmektedir.Böylelikle sınırlandırılan nesne ile tip güvenlik ihlallerinin önüne geçilmiş olacaktır.Aşağıda bounded types'leri kullanan basit bir örnek verilmektedir.



BoundedTypesEx1 sınıfında tanımlı jenerik parametrenin Number sınıfından türetildiği görülmektedir.Bu ifade,oluşturulacak nesne içeriklerinin sayısal tip olacağını derleyiciye garanti eder.

Başka bir örnekte ise 3 noktası verilen bir üçgenin çevresinin hesaplanması istenmektedir.Bunun için yine yukarıdaki gibi bir Number uyumlu sınıfa ihtiyacımız vardır.Çevre hesabı için Character,String gibi sınıflar işimize yaramayacaktır.




Yukarıdaki programda ise T ve V adında ipi tip jenerik tipi kullanılmıştır.T tipi Number nesneleri için kullanılırken,V ise herhangi bir nesne türü ile kullanılabilmektedir.
There has been no comment yet

Name:


Question/Comment
   Please verify the image




The Topics in Computer Science

Search this site for





 

Software & Algorithms

icon

In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning.

Programming Languages

icon

A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. It can be used to create programs to control the behavior of a machine. Java,C, C++,C#

Database

icon

A database is an organized collection of data. The data are typically organized to model aspects of reality in a way that supports processes requiring information.

Hardware

icon

Computer hardware is the collection of physical elements that constitutes a computer system. Computer hardware refers to the physical parts or components of a computer such as the monitor, memory, cpu.

Web Technologies

icon

Web development is a broad term for the work involved in developing a web site for the Internet or an intranet. Html,Css,JavaScript,ASP.Net,PHP are one of the most popular technologies. J2EE,Spring Boot, Servlet, JSP,JSF, ASP

Mobile Technologies

icon

Mobile application development is the process by which application software is developed for low-power handheld devices, such as personal digital assistants, enterprise digital assistants or mobile phones. J2ME

Network

icon

A computer network or data network is a telecommunications network that allows computers to exchange data. In computer networks, networked computing devices pass data to each other along data connections.

Operating Systems

icon

An operating system is software that manages computer hardware and software resources and provides common services for computer programs. The OS is an essential component of the system software in a computer system. Linux,Windows

Computer Science

icon

Computer science is the scientific and practical approach to computation and its applications.A computer scientist specializes in the theory of computation and the design of computational systems.