Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: cast with variable for classname

  1. #1
    Junior Member
    Join Date
    Apr 2018
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default cast with variable for classname

    Hi!

    Can you use some kind of variable like this ?

    var = String;
    String str = (var)io.readOject();

    var = Integer;
    int i = (var)io.readObject();

    Thanks for any help !!

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    172
    My Mood
    Asleep
    Thanks
    5
    Thanked 12 Times in 12 Posts

    Default Re: cast with variable for classname

    Please elaborate more
    Whatever you are, be a good one

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,287
    Thanks
    52
    Thanked 2,282 Times in 2,253 Posts

    Default Re: cast with variable for classname

    That syntax won't work. It might be done by using reflection.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Instanceof/cast doesnt work?
    By sci4me in forum Java Theory & Questions
    Replies: 0
    Last Post: May 10th, 2013, 08:53 PM
  2. Proper way to cast generics?
    By LastMagister in forum Collections and Generics
    Replies: 1
    Last Post: March 8th, 2013, 01:36 AM
  3. Decorator class cast exception
    By krishnaji_mkm@yahoo.co.in in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 7th, 2011, 04:38 AM
  4. className.main(new String[]{"filename.txt"}); - Help
    By knightmetal in forum Java Theory & Questions
    Replies: 4
    Last Post: August 25th, 2011, 07:22 AM
  5. Unsafe cast
    By Kerr in forum Collections and Generics
    Replies: 2
    Last Post: April 19th, 2011, 06:49 AM