Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Constructors with var-args?  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can a constructor with var-args be used when a no-arg constructor is needed?

Will this work for all cases like when in deserialization the superclass(not implementing serialization) should have no-arg constructor?

Thanks...
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class a
{
a(int ...x)
{
System.out.printf("%s","in var arg consturctor");
}
}
class NewClass extends a{

/** Creates a new instance of NewClass */

NewClass()
{
super();


}
public static void main(String s[])
{
new NewClass();
}


}
//it works
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,

Originally posted by Neha Bhattad:
Can a constructor with var-args be used when a no-arg constructor is needed?



can you show a situation where a no-arg constructor is needed?

Prahlad's example is just the other way round.


Bu.
[ August 26, 2007: Message edited by: Burkhard Hassel ]
 
Neha Bhattad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was mainly thinking about deserialization:
in deserialization the superclass(not implementing serialization) should have no-arg constructor else the readObject throws runtime exception.
What if the superclass has a no-arg constructor? Does it fit the bill?

The best way perhaps is to try it out...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!