Posted by 최윤석 on July 23, 1997 at 14:32:39:
In Reply to: 원래 자바는 유니온을 지원하지 않으니... posted by 윤경구 on July 21, 1997 at 16:43:58:
윤경구님의 말씀데로 입니다.
제 질문을 정확히 이해하시고
대답해 주셨군요... 감사합니다.
그래서 제가 간단히 만들어 사용해 보았는데
좀 불편 하지만 그런데로 사용할수 있었습니다.
아래에 제가만든 예제 입니다...
public class Union
{
protected int UnitSize;
protected int TotalSize;
protected int ArrayNumber;
public char[] data;
public Union( int size, int num )
{
TotalSize = size;
ArrayNumber = num;
UnitSize = size / num;
data = new char[TotalSize];
}
public void setValue( int index, char value )
{
data[index] = value;
}
public void setValue( int num, int index, char value )
{
data[ num * UnitSize + index ] = value;
}
public char getValue( int index )
{
return data[index];
}
public char getValue( int num, int index )
{
return data[ num * UnitSize + index ];
}
}