Java Interview Guide: How to Build Confidence With a Solid Understanding of Core Java Principles pdfdrive com



Yüklə 0,53 Mb.
Pdf görüntüsü
səhifə15/47
tarix06.05.2023
ölçüsü0,53 Mb.
#108601
1   ...   11   12   13   14   15   16   17   18   ...   47
Java Interview Guide

Generic Wildcards
Unlike arrays, generics are invariant, meaning that generic objects do not share
the same relationship as its types. For example, even though Integer extends
Number
, List does not extend List. The common
parent of List and List is the wildcard type
List
.
Wildcards can be used to create restrictions on generic types. For example,
the upper bounded wildcard List allows the
Number
type and all subclasses of Number. The lower bounded wildcard
List
allows the Number type and all superclasses
of Number.


Type Erasure
In order to preserve backwards compatibility, generic types are removed by the
compiler and replaced with object casts in a process called type erasure.
Type erasure prevents the need for legacy code to be recompiled, but it also
introduces several limitations. For example, generic exceptions are not allowed
because a catch block cannot tell the difference between
a GenericException and
a GenericException. Similarly, a class cannot implement
both Comparable and Comparable, because
without generic types they both represent the same interface.


Questions
What is the difference between a compile-time error and a runtime error?
What is the purpose of generics?
What are the different types of generic wildcards?
What is type erasure?
What are some of the limitations of generics?


Concurrency
Java supports concurrent programming through the use of threads. A thread
is a single path of execution in an application. The JVM typically launches
as a single process, spawning multiple threads that share its resources. Threads
that modify shared resources must be coordinated in order to prevent
unpredictable behavior.



Yüklə 0,53 Mb.

Dostları ilə paylaş:
1   ...   11   12   13   14   15   16   17   18   ...   47




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin