Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / June 2004

Tip: Looking for answers? Try searching our database.

Runtime instances creating

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pakhomenko Dmitry - 28 Apr 2004 10:46 GMT
   Hello, all. Anybody could help me
   I want to create insatnces of any classes in runtime. I know two ways
   1) using reflection and getting constructo
   2) using maging string "Class.forName(<className>).newInstance()

   Both methods work well, but... If class doesnt' have any declared cunstructors, instance creation will fail

   Thanks
   Pakhomenko Dmitry
Lars-Inge T?nnessen - 29 Apr 2004 15:23 GMT
>     If class doesnt' have any declared cunstructors, instance creation
will fail.

Make a wrapper.  =:o)

Regards,
Lars-Inge T?nnessen
www.larsinge.com
Pakhomenko Dmitry - 30 Apr 2004 05:06 GMT
>    Make a wrapper.  =:o
     Very helpful :) But it should be transparently for end user. Let me introduce my problem better. I've written classes for j# for supporting standard java RMI mechanism. So, now j# client could talk with java server using standart sun RMI technology. And back to front, j# server could serve java RMI clients. It was not easy, but now it is working :) There wer
many problems, for example j# serialize/deserialize stream a bit different from sun stream. So, I implemented custo
java like classes ObjectOutputStream, ObjectInputStream, and ObjectStreamClass in j#. Besides, .Net and sun have different ideologies so classes java.lang.Throwable and their inherited members have very different structures. So I added special processing in these classes for converting j# exceptions to java exceptions and back. But I haven't decided yet one little problem. Java class which will be serialized from j# or deserialized by j# have to contain DECLARED and PUBLIC constructor without any parameters. It's not problem, most likely it's just inconvenience

PS: Sorry for my terrible English, I'm from wild country - Russia :

      Best wishes
      Pakhomenko Dmitr

      http://pahomenko.narod.ru
George Birbilis [MVP J#] [9880] - 17 Jun 2004 22:30 GMT
> Java class which will be serialized from j# or deserialized by j# have to contain DECLARED and PUBLIC constructor without any parameters. It's not
problem,
> most likely it's just inconvenience.

isn't that the case with Sun Java too?
or do you find that just j# need the default public constructor available at
the class to have it deserialized?

at the Sun JVM side, maybe the "Proxy" class can help with such things, or
else maybe JNI has some useful call

btw, the idea is that you shouldn't be able to trick the JVM to instantiate
an object (make a class instance) for a class that has no default public
constructor, or has a private default constructor (for example it might have
a "private" default constructor to force all descendent classes not be
instantiatable too! [if it had "protected" or no default constructor a
descendent class could add a "public" constructor])

if you're interested to support Double, Long, etc. classes hardcode their
marshalling/unmarshalling instead or even better make a lookup hash, where
one passes a fully qualified class name (like "java.lang.Double") and gets
back a marshaller/unmarshaller class interface implementation (that takes an
"Object" [instance of the wanted class] and writes it to a stream [or
vice-versa])

e.g.

public interface Marshaller {
public void marshal(Object x, SomeOutputStream s);
}

public interface Unmarshaller {
public Object unmarshal(SomeInputStream s);
}

public class DoubleMarshallingSupport
implements Marshaller, Unmarshaller
{

public void marshal(Object x, SomeOutputStream s){
 s.writedouble(Double.doubleValue());
}

public Object unmarshal(SomeInputStream s){
 return new Double(s.readdouble());
}
}

or something like that

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
George Birbilis <birbilis@kagi.com> [J# MVP9880]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ QuickTime VCL and ActiveX controls (for PowerPoint/VB/Delphi etc.)
+ Plugs VCL and ActiveX controls (InterProcess/Internet communication)
+ TransFormations, VB6 forms to ASP.net WebForms convertion
http://www.kagi.com/birbilis
+ Robotics
http://www.mech.upatras.gr/~robgroup
........................................................................

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.