Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Why do Collections(save Arrays) allow only Objects?

 
Ranch Hand
Posts: 137
Hibernate Netbeans IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Posted By Monu Tripathi .... Perhaps it is; I do this in my spare time, usually ;) [sidebar: sigh! what a life?!]



If we could be able to answere "Why an IF construct accepts only boolean / booleanic results" than i hope we would be in a state to answere WHY of SUN Java's innovativenss & creativity
 
Marshal
Posts: 70206
280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sidharth Pallai wrote:If we could be able to answere "Why an IF construct accepts only boolean / booleanic results" . . .

How on earth could an "if-then-else" accept anything other than a Boolean value as its test?
 
Marshal
Posts: 25795
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:

Sidharth Pallai wrote:If we could be able to answere "Why an IF construct accepts only boolean / booleanic results" . . .

How on earth could an "if-then-else" accept anything other than a Boolean value as its test?



I think that might have been referring to other languages which accept innovative things like 0 and 1 as the conditions for if-statements. In other words there are rules in the language which coerce integer values (or possibly other junk for all I know) to boolean values. For example XSLT allows you to use a node-set as a condition for the xsl:if element by coercing empty sets to false and non-empty sets to true.
 
Campbell Ritchie
Marshal
Posts: 70206
280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, of course. In fact the theoretical basis for an if-then-else only takes boolean values for its test, but most production languages cheat by using 0 for false and non-zero (1, -1, etc)for true.
 
    Bookmark Topic Watch Topic
  • New Topic