Click here to Skip to main content
15,929,356 members
Home / Discussions / Java
   

Java

 
Questionjava browser application restrictions Pin
deostroll12-Jul-09 21:48
deostroll12-Jul-09 21:48 
AnswerRe: java browser application restrictions Pin
Nagy Vilmos12-Jul-09 23:05
professionalNagy Vilmos12-Jul-09 23:05 
GeneralRe: java browser application restrictions Pin
deostroll13-Jul-09 0:19
deostroll13-Jul-09 0:19 
AnswerRe: java browser application restrictions Pin
Tr@v22-Jul-09 10:16
Tr@v22-Jul-09 10:16 
QuestionrxtxSerial library multiple serial port listener registration and handling Pin
Kujtim Hyseni12-Jul-09 5:56
Kujtim Hyseni12-Jul-09 5:56 
QuestionHELP!HELP!HELP! Pin
kmnv11-Jul-09 9:52
kmnv11-Jul-09 9:52 
AnswerRe: HELP!HELP!HELP! Pin
Rajdeep.NET15-Jul-09 8:31
Rajdeep.NET15-Jul-09 8:31 
QuestionDifferent object types (references) Pin
Kujtim Hyseni10-Jul-09 6:58
Kujtim Hyseni10-Jul-09 6:58 
Hello,

I heave an array of objects which each object has some common parameters, but also is to be characterized by adequate specific object. For each object I use 'objectType' parammeter to differentiate, then the rest, I tried as follows (using 'Object' type) but it is not working. Here is the complete simplified code:

class DiffObjectClasses{ 
     public static void main(String [] args) 
     { 
           SerialObject so; 
           IPObject iob; 
            
           ObjectType ot[] = new ObjectType[3]; 
            
           ot[0].objectID=1; 
           ot[0].objectType=1; 
           so=new SerialObject(); 
           so.serialPortNo=21; 
           ot[0].objectContent=so; 
            
           ot[1].objectID=2; 
           ot[1].objectType=1; 
           so=new SerialObject(); 
           so.serialPortNo=21; 
           ot[1].objectContent=so; 
            
           ot[2].objectID=3; 
           ot[2].objectType=2; 
           iob=new IPObject(); 
           iob.host="localhost"; 
           iob.port=2200; 
           ot[2].objectContent=iob; 
            
           System.out.println("----------------------------"); 
           for(int indx=0; indx<ot.length;indx++) 
           { 
                 System.out.println("ObjID:"+ot[indx].objectID); 
                 System.out.println("ObjType:"+ot[indx].objectType); 
                 switch(ot[indx].objectType) 
                 { 
                       case 1: 
                                   so=(SerialObject)ot[indx].objectContent; 
                                   System.out.println("Serial port no:"+so.serialPortNo); 
                                   break; 
                       case 2: 
                                   iob=(IPObject)ot[indx].objectContent; 
                                   System.out.println("IP host:"+iob.host); 
                                   System.out.println("IP port:"+iob.port); 
                                   break;             
                 } 
           } 
     } 
} 
 
class ObjectType{ 
     int objectID; 
     int objectType; 
     Object objectContent; 
} 
 
class SerialObject{ 
     int serialPortNo; 
} 
 
class IPObject{ 
     String host=""; 
     int port; 
}


I've worked in C/C++, it was very simple by declaring 'void' member and then using implicit conversion as here but it sin't working in Java.

Kujtim
AnswerRe: Different object types (references) Pin
harold aptroot10-Jul-09 8:10
harold aptroot10-Jul-09 8:10 
GeneralRe: Different object types (references) [modified] Pin
Kujtim Hyseni10-Jul-09 8:17
Kujtim Hyseni10-Jul-09 8:17 
GeneralRe: Different object types (references) Pin
harold aptroot10-Jul-09 8:34
harold aptroot10-Jul-09 8:34 
GeneralRe: Different object types (references) Pin
Kujtim Hyseni10-Jul-09 9:49
Kujtim Hyseni10-Jul-09 9:49 
GeneralRe: Different object types (references) Pin
harold aptroot10-Jul-09 10:07
harold aptroot10-Jul-09 10:07 
GeneralRe: Different object types (references) Pin
Kujtim Hyseni10-Jul-09 10:43
Kujtim Hyseni10-Jul-09 10:43 
GeneralRe: Different object types (references) Pin
harold aptroot10-Jul-09 10:51
harold aptroot10-Jul-09 10:51 
AnswerRe: Solution - Different object types (references) Pin
Kujtim Hyseni10-Jul-09 10:54
Kujtim Hyseni10-Jul-09 10:54 
Question[Message Deleted] Pin
ana_ochia8-Jul-09 2:20
ana_ochia8-Jul-09 2:20 
AnswerRe: is there any chance that the Four square game be programmed using JAVA? Pin
Nagy Vilmos8-Jul-09 21:55
professionalNagy Vilmos8-Jul-09 21:55 
GeneralRe: is there any chance that the Four square game be programmed using JAVA? Pin
ana_ochia9-Jul-09 14:05
ana_ochia9-Jul-09 14:05 
GeneralRe: is there any chance that the Four square game be programmed using JAVA? Pin
Cedric Moonen9-Jul-09 20:22
Cedric Moonen9-Jul-09 20:22 
GeneralRe: is there any chance that the Four square game be programmed using JAVA? Pin
Nagy Vilmos9-Jul-09 22:03
professionalNagy Vilmos9-Jul-09 22:03 
QuestionLooking for some guideance or advice on messaging implementation Pin
tas28267-Jul-09 6:57
tas28267-Jul-09 6:57 
AnswerRe: Looking for some guideance or advice on messaging implementation Pin
David Skelly7-Jul-09 22:33
David Skelly7-Jul-09 22:33 
QuestionsortTable Help Pin
samo12055-Jul-09 9:49
samo12055-Jul-09 9:49 
AnswerRe: sortTable Help Pin
David Skelly5-Jul-09 22:10
David Skelly5-Jul-09 22:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.