java - Instantiate an abstract class using another object's method? -


this question has answer here:

i've been looking creating barcode scanner program, , in research came across i've never seen before, , i'm not sure doing...

here's snippet of program, including line don't understand:

import javax.comm.*;      public class invscan implements serialporteventlistener {   static commportidentifier portid1; serialport serialport1;   public invscan(){     serialport1 = (serialport) portid1.open("invscan", 2000); //what mean?  } 

see line commented "what mean?". serialport abstract class... know abstract classes can instantiated using anonymous class, i've never seen before. line of code came tutorial program designed related want do, author didn't explain going on here (or maybe didn't understand?). notes say:

we instantiating serialport object executing portid1’s open() method. recall portid1 comportidentifier object , open() method comes comportidentifier.

i've done research, , can't find example of whatever going on here (probably because don't know call it, really).

this isn't essential program, can redesign (and not script kiddie, haha), it's bugging me don't know going on in line.

the actual object instantiation of non-abstract subclass derived serialport. provide guarantees abstract methods have been defined within instantiated object. internally, like:

public class commportidentifier ... {  ...      public commport open(java.lang.string appname, int timeout)             throws portinuseexception {          commport val = new nonabstractcommport( ... );          // here          return val;     }  ...  } 

being abstract subclass of commport, cast serialport little risky unless there guarantees actual return type of object subclass of serialport.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -