SlideShare a Scribd company logo
This slide intentionally left blank.
Tricks with Types

       How to get fired
 with the Java type system.

            Shevek
      shevek@anarres.org
Compilers
●   The job of the compiler is turn your source into
    binary.

●   That's all, right?

●   No, it also helps you write correct code.

●   The type system is the most significant tool in the
    arsenal.
Java

●   Java is simple.
●   Java does not allow language extensions.
●   It has primitive types and classes.
●   It has single inheritance and interfaces.

●   So what can we do?

●   It doesn't get interesting yet.
Java 1.5

●   Parameterized types.
    ●     List<X>

        public interface Foo<X> {
            public void add(X value);
            public X get(int index);
        }

●   Now the compiler can check our code.
        Foo<String> x = ...;

        x.add(“bar”); // OK

        x.add(5);     // Not OK

        String value = x.get(4);   // Note, no cast.
Where Can We Use Parameters?
●   More places than you think!
     public class Foo<X> { // Here, we all know.

         @Override
         public <T> T add(Foo<T> remote, T value) { // Also, here!
             ...
         }
     }



●   Now we can say “These two things are of the
    same type.” without knowing the type!
Java 1.5 Bytecode
●   What happens underneath?
    public interface Foo<X> {
        public void add(X value); // It's an Object.
    }

    public class MyFoo implements Foo<String> {
        @Override
        public void add(String value) { // This can't override (Object)
              ...
        }
    }

    public class MyFoo implements Foo<String> {

        public void add(String value) {
            ...
        }

        @Override
        public synthetic void add(Object value) {// So this does.
            add((String)value);
        }
    }
Bounded Parameters
●   We can give required properties of the
    parameter X.
    public interface Foo<X extends Bar> {
        public void add(X value) {
              // Now we can use the properties of Bar, but not X.
        }
    }

    public class MyBar extends Bar { }
    public class YourBar extends Bar { }

    Foo<MyBar>        // Valid
    Foo<YourBar>      // Valid
    Foo<String>       // Invalid
More Power to Type Bounds
●   Help us write correct code.
    public interface MyContainer<X> {
        public List<X> void getValues();
    }

    MyContainer<String> x = …;
    List<String> l = x.getValues();
    x.add(“foo”);

●   Did we just modify an internal data structure?
●   Can the compiler help us find out?
    public interface MyContainer<X> {
        public List<? extends X> void getValues();
    }

    MyContainer<String> x = …;
    List<? extends String> l = x.getValues();
    x.add(“foo”); // Illegal – can't create a value of type unknown.
Even More Power to Type Bounds
●   We did read-only. Can we do write-only?
    public interface MyContainer<X> {
        public List<? super X> void getTarget();
    }

    MyContainer<String> x = …;
    List<String> l = x.getTarget();
    x.add(“foo”); // We're allowed to add Strings, or anything below.
    x.get(...);   // Illegal, since we don't know the return type.
What Does a Bound Tell Us?
●   It doesn't tell us the type, just the properties.
●   We can have multiple bounds!
     public interface MyContainer {
         public <T extends JComponent & MyPanel> void add(T panel) {
               // Now we can use the properties of JComponent
               // and MyPanel.
         }
     }


●   Now, we specified multiple behaviours in a
    language with only single inheritance!
●   I forget what bytecode it compiles here.
Types Are Powerful
●   Types are the primary tool for the compiler to
    prove correctness of code.

●   If you used a cast, you did something wrong.

●   Say what you mean, and the rest will follow.
Thank you




            Guh.....? What just happened?

More Related Content

What's hot

Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
Cate Huston
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
SadhanaParameswaran
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
Sumit Raj
 
Lecture5
Lecture5Lecture5
Lecture5
Sunil Gupta
 
Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScript
Rajat Saxena
 
Pointers & functions
Pointers &  functionsPointers &  functions
Pointers & functions
Manjitsing Valvi
 
Lesson 2 php data types
Lesson 2   php data typesLesson 2   php data types
Lesson 2 php data types
MLG College of Learning, Inc
 
Cross platform native development in f#
Cross platform native development in f#Cross platform native development in f#
Cross platform native development in f#
David Kay
 
Java Basic day-1
Java Basic day-1Java Basic day-1
Java Basic day-1
Kamlesh Singh
 
Unsafe to typesafe
Unsafe to typesafeUnsafe to typesafe
Unsafe to typesafe
regisleray
 
Optionals by Matt Faluotico
Optionals by Matt FaluoticoOptionals by Matt Faluotico
Optionals by Matt Faluotico
WithTheBest
 
Os Welton
Os WeltonOs Welton
Os Welton
oscon2007
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
Jared Roesch
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
MLG College of Learning, Inc
 
PHP
 PHP PHP
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
sandeep54552
 
Learn To Code: Diving deep into java
Learn To Code: Diving deep into javaLearn To Code: Diving deep into java
Learn To Code: Diving deep into java
SadhanaParameswaran
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
Sujan Mia
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Effective PHP. Part 2
Effective PHP. Part 2Effective PHP. Part 2
Effective PHP. Part 2
Vasily Kartashov
 

What's hot (20)

Java Building Blocks
Java Building BlocksJava Building Blocks
Java Building Blocks
 
Learn To Code: Introduction to java
Learn To Code: Introduction to javaLearn To Code: Introduction to java
Learn To Code: Introduction to java
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
Lecture5
Lecture5Lecture5
Lecture5
 
Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScript
 
Pointers & functions
Pointers &  functionsPointers &  functions
Pointers & functions
 
Lesson 2 php data types
Lesson 2   php data typesLesson 2   php data types
Lesson 2 php data types
 
Cross platform native development in f#
Cross platform native development in f#Cross platform native development in f#
Cross platform native development in f#
 
Java Basic day-1
Java Basic day-1Java Basic day-1
Java Basic day-1
 
Unsafe to typesafe
Unsafe to typesafeUnsafe to typesafe
Unsafe to typesafe
 
Optionals by Matt Faluotico
Optionals by Matt FaluoticoOptionals by Matt Faluotico
Optionals by Matt Faluotico
 
Os Welton
Os WeltonOs Welton
Os Welton
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
 
Lesson 6 php if...else...elseif statements
Lesson 6   php if...else...elseif statementsLesson 6   php if...else...elseif statements
Lesson 6 php if...else...elseif statements
 
PHP
 PHP PHP
PHP
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
 
Learn To Code: Diving deep into java
Learn To Code: Diving deep into javaLearn To Code: Diving deep into java
Learn To Code: Diving deep into java
 
Abstract class in c++
Abstract class in c++Abstract class in c++
Abstract class in c++
 
class and objects
class and objectsclass and objects
class and objects
 
Effective PHP. Part 2
Effective PHP. Part 2Effective PHP. Part 2
Effective PHP. Part 2
 

Viewers also liked

Digital Angle Overview
Digital Angle   OverviewDigital Angle   Overview
Digital Angle Overview
Eamon Tuhami
 
Desfile 7 de setembro 2012 - Escola Municipal Antonio Rayol
Desfile 7 de setembro 2012 - Escola Municipal Antonio RayolDesfile 7 de setembro 2012 - Escola Municipal Antonio Rayol
Desfile 7 de setembro 2012 - Escola Municipal Antonio Rayol
Thais Beatriz
 
Viral seeding creds 2015
Viral seeding creds 2015Viral seeding creds 2015
Viral seeding creds 2015
viralseeding
 
Money ball english film reveiw
Money ball english film reveiw Money ball english film reveiw
Money ball english film reveiw
Deepak Somaji-Sawant
 
English
EnglishEnglish
English
rouns
 
Newer film programming content type ii
Newer film programming content type iiNewer film programming content type ii
Newer film programming content type ii
Deepak Somaji-Sawant
 
Ordering numbers
Ordering numbersOrdering numbers
Ordering numbers
carinmcatee
 
Grow with Gemara
Grow with GemaraGrow with Gemara
Grow with Gemara
perlmutter
 
Newer film programming content concept
Newer film programming content conceptNewer film programming content concept
Newer film programming content concept
Deepak Somaji-Sawant
 
Johnny english film direction quality points
Johnny english film direction  quality points Johnny english film direction  quality points
Johnny english film direction quality points
Deepak Somaji-Sawant
 
^^ Film director recognition could be from me ^^ .
^^  Film director recognition could be  from me ^^ .^^  Film director recognition could be  from me ^^ .
^^ Film director recognition could be from me ^^ .
Deepak Somaji-Sawant
 
English film reveiw war horse
English film reveiw war horse  English film reveiw war horse
English film reveiw war horse
Deepak Somaji-Sawant
 
Film direction quality points receiw for the muppets english film
Film direction quality points receiw for  the muppets  english film  Film direction quality points receiw for  the muppets  english film
Film direction quality points receiw for the muppets english film
Deepak Somaji-Sawant
 
Energysources
EnergysourcesEnergysources
Energysources
rouns
 
Grow With Gemara
Grow With GemaraGrow With Gemara
Grow With Gemara
perlmutter
 
Презентация+портфолио дизайн-студии "Кефир" (Харьков)
Презентация+портфолио дизайн-студии "Кефир" (Харьков)Презентация+портфолио дизайн-студии "Кефир" (Харьков)
Презентация+портфолио дизайн-студии "Кефир" (Харьков)
Kefir Design Studio
 

Viewers also liked (16)

Digital Angle Overview
Digital Angle   OverviewDigital Angle   Overview
Digital Angle Overview
 
Desfile 7 de setembro 2012 - Escola Municipal Antonio Rayol
Desfile 7 de setembro 2012 - Escola Municipal Antonio RayolDesfile 7 de setembro 2012 - Escola Municipal Antonio Rayol
Desfile 7 de setembro 2012 - Escola Municipal Antonio Rayol
 
Viral seeding creds 2015
Viral seeding creds 2015Viral seeding creds 2015
Viral seeding creds 2015
 
Money ball english film reveiw
Money ball english film reveiw Money ball english film reveiw
Money ball english film reveiw
 
English
EnglishEnglish
English
 
Newer film programming content type ii
Newer film programming content type iiNewer film programming content type ii
Newer film programming content type ii
 
Ordering numbers
Ordering numbersOrdering numbers
Ordering numbers
 
Grow with Gemara
Grow with GemaraGrow with Gemara
Grow with Gemara
 
Newer film programming content concept
Newer film programming content conceptNewer film programming content concept
Newer film programming content concept
 
Johnny english film direction quality points
Johnny english film direction  quality points Johnny english film direction  quality points
Johnny english film direction quality points
 
^^ Film director recognition could be from me ^^ .
^^  Film director recognition could be  from me ^^ .^^  Film director recognition could be  from me ^^ .
^^ Film director recognition could be from me ^^ .
 
English film reveiw war horse
English film reveiw war horse  English film reveiw war horse
English film reveiw war horse
 
Film direction quality points receiw for the muppets english film
Film direction quality points receiw for  the muppets  english film  Film direction quality points receiw for  the muppets  english film
Film direction quality points receiw for the muppets english film
 
Energysources
EnergysourcesEnergysources
Energysources
 
Grow With Gemara
Grow With GemaraGrow With Gemara
Grow With Gemara
 
Презентация+портфолио дизайн-студии "Кефир" (Харьков)
Презентация+портфолио дизайн-студии "Кефир" (Харьков)Презентация+портфолио дизайн-студии "Кефир" (Харьков)
Презентация+портфолио дизайн-студии "Кефир" (Харьков)
 

Similar to Getting Fired with Java Types

Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
HelpWithAssignment.com
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
HelpWithAssignment.com
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
Haim Yadid
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
julien pauli
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
Daniele Pozzobon
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
GeorgePeterBanyard
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
intelliyole
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
Luca Guadagnini
 
Java
JavaJava
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
MikeAdva
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and Javascript
Kamil Toman
 
C tutorial
C tutorialC tutorial
C tutorial
Khan Rahimeen
 
C tutorial
C tutorialC tutorial
C tutorial
tuncay123
 
C tutorial
C tutorialC tutorial
C tutorial
Anuja Lad
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
Basil N G
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Chris Adamson
 
pure-functional-programming.pdf
pure-functional-programming.pdfpure-functional-programming.pdf
pure-functional-programming.pdf
PuneetChaturvedi23
 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdf
Spam92
 
Linq Introduction
Linq IntroductionLinq Introduction
Linq Introduction
Neeraj Kaushik
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
Alfonso Garcia-Caro
 

Similar to Getting Fired with Java Types (20)

Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Taking Kotlin to production, Seriously
Taking Kotlin to production, SeriouslyTaking Kotlin to production, Seriously
Taking Kotlin to production, Seriously
 
PHP7 is coming
PHP7 is comingPHP7 is coming
PHP7 is coming
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
 
Java
JavaJava
Java
 
Internet programming slide - java.ppt
Internet programming slide - java.pptInternet programming slide - java.ppt
Internet programming slide - java.ppt
 
Fantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and JavascriptFantom - Programming Language for JVM, CLR, and Javascript
Fantom - Programming Language for JVM, CLR, and Javascript
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
Go Programming language, golang
Go Programming language, golangGo Programming language, golang
Go Programming language, golang
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
pure-functional-programming.pdf
pure-functional-programming.pdfpure-functional-programming.pdf
pure-functional-programming.pdf
 
golang_refcard.pdf
golang_refcard.pdfgolang_refcard.pdf
golang_refcard.pdf
 
Linq Introduction
Linq IntroductionLinq Introduction
Linq Introduction
 
Functional Programming in C# and F#
Functional Programming in C# and F#Functional Programming in C# and F#
Functional Programming in C# and F#
 

Recently uploaded

The History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal EmbeddingsThe History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal Embeddings
Zilliz
 
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Zilliz
 
UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...
UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...
UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...
FIDO Alliance
 
It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...
Zilliz
 
Mastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for SuccessMastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for Success
David Wilson
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
shanihomely
 
Gen AI: Privacy Risks of Large Language Models (LLMs)
Gen AI: Privacy Risks of Large Language Models (LLMs)Gen AI: Privacy Risks of Large Language Models (LLMs)
Gen AI: Privacy Risks of Large Language Models (LLMs)
Debmalya Biswas
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
BrainSell Technologies
 
Tailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer InsightsTailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer Insights
SynapseIndia
 
Finetuning GenAI For Hacking and Defending
Finetuning GenAI For Hacking and DefendingFinetuning GenAI For Hacking and Defending
Finetuning GenAI For Hacking and Defending
Priyanka Aash
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
shyamraj55
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
ankush9927
 
Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
Bhajan Mehta
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
Steven Carlson
 
LeadMagnet IQ Review: Unlock the Secret to Effortless Traffic and Leads.pdf
LeadMagnet IQ Review:  Unlock the Secret to Effortless Traffic and Leads.pdfLeadMagnet IQ Review:  Unlock the Secret to Effortless Traffic and Leads.pdf
LeadMagnet IQ Review: Unlock the Secret to Effortless Traffic and Leads.pdf
SelfMade bd
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
Retrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with RagasRetrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with Ragas
Zilliz
 
The Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - CoatueThe Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - Coatue
Razin Mustafiz
 
Improving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning ContentImproving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning Content
Enterprise Knowledge
 
Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024
Nicolás Lopéz
 

Recently uploaded (20)

The History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal EmbeddingsThe History of Embeddings & Multimodal Embeddings
The History of Embeddings & Multimodal Embeddings
 
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
Garbage In, Garbage Out: Why poor data curation is killing your AI models (an...
 
UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...
UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...
UX Webinar Series: Essentials for Adopting Passkeys as the Foundation of your...
 
It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...It's your unstructured data: How to get your GenAI app to production (and spe...
It's your unstructured data: How to get your GenAI app to production (and spe...
 
Mastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for SuccessMastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for Success
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
 
Gen AI: Privacy Risks of Large Language Models (LLMs)
Gen AI: Privacy Risks of Large Language Models (LLMs)Gen AI: Privacy Risks of Large Language Models (LLMs)
Gen AI: Privacy Risks of Large Language Models (LLMs)
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
 
Tailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer InsightsTailored CRM Software Development for Enhanced Customer Insights
Tailored CRM Software Development for Enhanced Customer Insights
 
Finetuning GenAI For Hacking and Defending
Finetuning GenAI For Hacking and DefendingFinetuning GenAI For Hacking and Defending
Finetuning GenAI For Hacking and Defending
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
 
Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
 
LeadMagnet IQ Review: Unlock the Secret to Effortless Traffic and Leads.pdf
LeadMagnet IQ Review:  Unlock the Secret to Effortless Traffic and Leads.pdfLeadMagnet IQ Review:  Unlock the Secret to Effortless Traffic and Leads.pdf
LeadMagnet IQ Review: Unlock the Secret to Effortless Traffic and Leads.pdf
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
 
Retrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with RagasRetrieval Augmented Generation Evaluation with Ragas
Retrieval Augmented Generation Evaluation with Ragas
 
The Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - CoatueThe Path to General-Purpose Robots - Coatue
The Path to General-Purpose Robots - Coatue
 
Improving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning ContentImproving Learning Content Efficiency with Reusable Learning Content
Improving Learning Content Efficiency with Reusable Learning Content
 
Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024Vertex AI Agent Builder - GDG Alicante - Julio 2024
Vertex AI Agent Builder - GDG Alicante - Julio 2024
 

Getting Fired with Java Types

  • 2. Tricks with Types How to get fired with the Java type system. Shevek shevek@anarres.org
  • 3. Compilers ● The job of the compiler is turn your source into binary. ● That's all, right? ● No, it also helps you write correct code. ● The type system is the most significant tool in the arsenal.
  • 4. Java ● Java is simple. ● Java does not allow language extensions. ● It has primitive types and classes. ● It has single inheritance and interfaces. ● So what can we do? ● It doesn't get interesting yet.
  • 5. Java 1.5 ● Parameterized types. ● List<X> public interface Foo<X> { public void add(X value); public X get(int index); } ● Now the compiler can check our code. Foo<String> x = ...; x.add(“bar”); // OK x.add(5); // Not OK String value = x.get(4); // Note, no cast.
  • 6. Where Can We Use Parameters? ● More places than you think! public class Foo<X> { // Here, we all know. @Override public <T> T add(Foo<T> remote, T value) { // Also, here! ... } } ● Now we can say “These two things are of the same type.” without knowing the type!
  • 7. Java 1.5 Bytecode ● What happens underneath? public interface Foo<X> { public void add(X value); // It's an Object. } public class MyFoo implements Foo<String> { @Override public void add(String value) { // This can't override (Object) ... } } public class MyFoo implements Foo<String> { public void add(String value) { ... } @Override public synthetic void add(Object value) {// So this does. add((String)value); } }
  • 8. Bounded Parameters ● We can give required properties of the parameter X. public interface Foo<X extends Bar> { public void add(X value) { // Now we can use the properties of Bar, but not X. } } public class MyBar extends Bar { } public class YourBar extends Bar { } Foo<MyBar> // Valid Foo<YourBar> // Valid Foo<String> // Invalid
  • 9. More Power to Type Bounds ● Help us write correct code. public interface MyContainer<X> { public List<X> void getValues(); } MyContainer<String> x = …; List<String> l = x.getValues(); x.add(“foo”); ● Did we just modify an internal data structure? ● Can the compiler help us find out? public interface MyContainer<X> { public List<? extends X> void getValues(); } MyContainer<String> x = …; List<? extends String> l = x.getValues(); x.add(“foo”); // Illegal – can't create a value of type unknown.
  • 10. Even More Power to Type Bounds ● We did read-only. Can we do write-only? public interface MyContainer<X> { public List<? super X> void getTarget(); } MyContainer<String> x = …; List<String> l = x.getTarget(); x.add(“foo”); // We're allowed to add Strings, or anything below. x.get(...); // Illegal, since we don't know the return type.
  • 11. What Does a Bound Tell Us? ● It doesn't tell us the type, just the properties. ● We can have multiple bounds! public interface MyContainer { public <T extends JComponent & MyPanel> void add(T panel) { // Now we can use the properties of JComponent // and MyPanel. } } ● Now, we specified multiple behaviours in a language with only single inheritance! ● I forget what bytecode it compiles here.
  • 12. Types Are Powerful ● Types are the primary tool for the compiler to prove correctness of code. ● If you used a cast, you did something wrong. ● Say what you mean, and the rest will follow.
  • 13. Thank you Guh.....? What just happened?