问个低级的问题:下面这段是什么意思呀? @TestTargets是什么意思呀?
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long[].class, int.class}
),
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Test vibrate",
method = "vibrate",
args = {long.class}
)
})
/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */package android.os.cts;import android.content.Context;
import android.os.Vibrator;
import android.test.AndroidTestCase;
import android.util.Log;
import dalvik.annotation.TestTargets;
import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestLevel;
import dalvik.annotation.TestTargetClass;@TestTargetClass(Vibrator.class)
public class VibratorTest extends AndroidTestCase {  private Vibrator mVibrator;  @Override
  protected void setUp() throws Exception {
  super.setUp();
  mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
  }  @TestTargetNew(
  level = TestLevel.COMPLETE,
  notes = "Test cancel()",
  method = "cancel",
  args = {}
  )
  public void testVibratorCancel() {
  try {
  mVibrator.vibrate(1000);
  } catch (Exception e) {
  fail("testVibratorCancel failed!");
  }
  sleep();
  try {
  mVibrator.cancel();
  } catch (Exception e) {
  fail("testVibratorCancel failed!");
  }
  }  @TestTargets({
  @TestTargetNew(
  level = TestLevel.COMPLETE,
  notes = "Test vibrate",
  method = "vibrate",
  args = {long[].class, int.class}
  ),
  @TestTargetNew(
  level = TestLevel.COMPLETE,
  notes = "Test vibrate",
  method = "vibrate",
  args = {long.class}
  )
  })
  public void testVibratePattern() {
  long[] pattern = {100, 200, 400, 800, 1600};
  try {
  mVibrator.vibrate(pattern, 3);
  } catch (Exception e) {
  fail("vibrate failed!");
  }
  try {
  mVibrator.vibrate(pattern, 10);
  fail("Should throw ArrayIndexOutOfBoundsException");
  } catch (ArrayIndexOutOfBoundsException e) {
  }
  sleep();
  }  @TestTargetNew(
  level = TestLevel.COMPLETE,
  notes = "Test vibrator with multi thread.",
  method = "vibrate",
  args = {long.class}
  )
  public void testVibrateMultiThread() {
  Log.d("*******VibratorTest", "MultiTreadTest");
  new Thread(new Runnable() {
  public void run() {
  Log.d("*******VibratorTest", "Thread 1");
  try {
  mVibrator.vibrate(100);
  } catch (Exception e) {
  fail("MultiThread fail1");
  }
  }
  }).start();
  new Thread(new Runnable() {
  public void run() {
  Log.d("*******VibratorTest", "Thread 2");
  try {
  // This test only get two threads to run vibrator at the same time
  // for a functional test,
  // but it can not verify if the second thread get the precedence.
  mVibrator.vibrate(1000);
  } catch (Exception e) {
  fail("MultiThread fail2");
  }
  }
  }).start();
  sleep();
  }  private void sleep() {
  try {
  Thread.sleep(10000);
  } catch (Exception e) {
  }
  }
}

解决方案 »

  1.   

    这应该是一些注释标记之类的,用来生成API 文档
      

  2.   

    Java5之后就出现了Java Annotation(JSR 175),第一眼看上去很像是C/C++的预编译,或者条件编译。可以告诉编译器应该做些什么事情之类的,但是情况其实并非如此,这个东西还是很有些不同之处,从一个用户的角度看,大体上可以用来做三件事体:1. 编译器注释。JSR175提供了几个默认的Annotation,包括@Deprecated、@Override和@SuppressWarnings2.文档化支持。Sun说可以替代JavaDoc的一些用途,但是也并没有新增什么,而且和注释相比,Annotation有作用域的限制,即不可以放到代码的各个位置,支持:TYPE、FIELD、METHOD、PARAMETER、CONSTRUCTOR、LOCAL_VARIABLE、 ANNOTATION_TYPE、PACKAGE。当然这些位置适用于所有的Annotation。3.运行时支持。Annotation可以混合代码和元代码,而且支持设定到底是否在字节码中包含Annotation。如果包含,则可以使用 Reflection激活这些Annotation。Sun给出了类似单元测试的例子。不过似乎和我无关,Junit已经干的很不错了。感觉Annotation似乎是一个大而全的方案,但是反而无法获得更多的应用。作为编译器注释,显然没有ifdef能力那么强,作为文档化支持,Javadoc早就广泛应用,作为runtime支持,则Junit这类物件也很完善了。XDoclet Team不过XDoclet看上去是有希望的项目,这玩意儿可以通过源代码中的注释标签生成多种多样的副产品,包括源代码、接口、XML、文档等等。本来是没有什么好处的,但是目前J2EE的复杂性导致的大量冗余工作却可以使用注释来消除,具有如下好处: