Warning: Declaration of PageLinesBanners::section_template($clone_id) should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/banners/section.php on line 205

Warning: Declaration of PageLinesFeatures::section_template($clone_id) should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/features/section.php on line 254

Warning: Declaration of PageLinesFeatures::section_head($clone_id) should be compatible with PageLinesSection::section_head() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/features/section.php on line 61

Warning: Declaration of PageLinesHighlight::section_template($clone_id) should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/highlight/section.php on line 94

Warning: Declaration of PageLinesCarousel::section_template($clone_id) should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/carousel/section.php on line 168

Warning: Declaration of PLheroUnit::section_template($clone_id) should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/hero/section.php on line 140

Warning: Declaration of PLNavBar::section_template($clone_id, $location = '') should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/navbar/section.php on line 199

Warning: Declaration of PLMasthead::section_template($clone_id) should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/masthead/section.php on line 178

Warning: Declaration of PageLinesQuickSlider::section_template($clone_id) should be compatible with PageLinesSection::section_template() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/quickslider/section.php on line 59

Warning: Declaration of PageLinesQuickSlider::section_head($clone_id) should be compatible with PageLinesSection::section_head() in /home/c0nannet/public_html/blog/wp-content/themes/pagelines/sections/quickslider/section.php on line 29
c0nan.net | Awesome<Generics extends Magic>

What is Java generics? It is the ability  defining a scope without really knowing the scope, but knowing limitations to the scope. Generics was the obvious follow up tot the concept of interfaces. Taking abstract to a whole new level of awesomeness!!!

Let me explain in the most simplest ways I can think off:

1. You have a hosepipe

2. You want to fit odds and ends to the hosepipe (sprayGun)

3. you need to develop a middle object connector, interface for these objects to fit onto the hosepipe

4. you want the connector to be able to do a specific set of access ways (connectToPipe, connectToConnector, sendWater, recieveWater)

5. you want the connector to have a set expected input, and expected outputs (waterFlow,5mmWaterFlow,3mmWaterFlow)

So we begin:

HosePipe.java

public class HosePipe extends Connector<WaterFlow5mm>{
   public void sendWaterflow(WaterFlow5mm waterflow){
      // Do whatever to the water that was sent to me
      System.out.println(waterflow.getWater().toString(););
   }
   public WaterFlow5mm recieveWaterflow(){
      return new WaterFlow5mm();
   }
}

SprayGun.java

public class SprayGun extends Connector<WaterFlow5mm>{
    public void sendWaterflow(WaterFlow5mm waterflow){
       // Do whatever to the water that was sent to me
       System.out.println(waterflow.getWater().toString(););
    } 

     public WaterFlow5mm recieveWaterflow(){
        return return new WaterFlow5mm();
     }

 }

Water.java

public class Water(){

private int oxygen = 1;
private int hydrogen = 2
public int getOxygen(){
  return oxygen;
}

public int getHydrogen (){
   return hydrogen ;
}

}

WaterFlow.java

public abstract class WaterFlow(){
public Water[] getWater();

}

WaterFlow5mm.java

public class WaterFlow5mm(){
public Water[] getWater(){

return new Water[5];

}

}

Connector.java

public abstract class Connector<A extends WaterFlow> implements Connectable<A>{

boolean connectToPipe(){

//click

};

boolean connectToOdds(){

//click

};

public abstract void sendWater(A waterflow);

public abstract A recieveWaterflow();

}

Connectable.java

public interface Connectable<A extends WaterFlow>{

boolean connectToPipe();

boolean connectToOdds();

void sendWaterflow(A waterflow);

A recieveWaterflow();

}

Now there are many more examples how generics can be used to simplify 'n project, but also be careful NOT to over complicate your project with generics.
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *