Null object

Revision as of 02:29, 31 July 2008 by rosettacode>Waldorf (Added Ada)

Null (or nil) is the computer science concept of an undefined or unbound object. Some languages have an explicit way to access the null object, and some don't.

Task
Null object
You are encouraged to solve this task according to the task description, using any language you may know.

Show how to access null in your language by checking to see if an object is equivalent to the null object.

Ada

<Ada>with Ada.Text_Io;

if Object = null then

  Ada.Text_Io.Put_line("object is null");

end if;</Ada>

C

C's access to null is by way of a macro which simply evaluates to 0. <c>if(object == NULL){

  printf("object is null");

}</c>

C++

C++'s access to null is (as in C) by way of a macro which simply evaluates to 0. <cpp>#include<stdio>

if(object == NULL){

  cout << "object is null";

}</cpp>

Java

<java>if(object == null){

  System.out.println("object is null");

}</java>

Ruby

if object == nil

  puts "object is null"

end