You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

WeakishReference.java 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2000-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.util;
  18. import org.apache.tools.ant.BuildException;
  19. import org.apache.tools.ant.util.optional.WeakishReference12;
  20. import java.lang.reflect.Constructor;
  21. /**
  22. * This is a weak reference on java1.2 and up, that is all
  23. * platforms Ant1.6 supports.
  24. * @since ant1.6
  25. */
  26. public abstract class WeakishReference {
  27. /**
  28. * create the appropriate type of reference for the java version
  29. * @param object
  30. * @return reference to the Object.
  31. */
  32. public static WeakishReference createReference(Object object) {
  33. return new WeakishReference12(object);
  34. }
  35. /**
  36. * Returns this reference object's referent. If this reference object has
  37. * been cleared, then this method returns <code>null</code>.
  38. *
  39. * @return The object to which this reference refers, or
  40. * <code>null</code> if this reference object has been cleared
  41. */
  42. public abstract Object get();
  43. /**
  44. * A hard reference for Java 1.1.
  45. * Hopefully nobody is using this.
  46. */
  47. public static class HardReference extends WeakishReference {
  48. private Object object;
  49. /**
  50. * construct
  51. * @param object
  52. */
  53. public HardReference(Object object) {
  54. this.object = object;
  55. }
  56. /**
  57. * Returns this reference object's referent.
  58. */
  59. public Object get() {
  60. return object;
  61. }
  62. }
  63. }