首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何制作我的程序的JAVADOC?

如何制作我的程序的JAVADOC?
EN

Stack Overflow用户
提问于 2018-10-17 03:27:25
回答 1查看 0关注 0票数 0

这是我的代码

public class Client
{
   protected int cod;
   protected String name;

   public void setCod(int cod) throws Exception
   {
      if(cod==null)
      throw new Exception("Invalid code!");

      this.cod = cod;
   }

   public int getCod()
   {
      return this.cod;
   }

   public void setName(String name) throws Exception
   {
      if(name==null || name.equals("")
      throw new Exception("Invalid name!");

      this.name = name;
   }

   public String getName()
   {
      return this.name;
   }

   public Client(int cod, String name) throws Exception
   {
      this.setCod(cod);
      this.setName(name);
   }

   public boolean equals(Object obj)
   {
      if(this==obj)
      return true;

      if(obj==null)
      return false;

      if(!(obj instanceof Client))
      return false;

      Client client = (Client)obj;

      if(this.cod!=client.cod)
      return false;

      if(this.name!=client.name)
      return false;

      return true;
   }

   public String toString()
   {
      return "Code: " + this.cod + "\n" +
             "Name: " + this.name;
   }

   public int hashCode()
   {
      int ret = 444;

      ret += ret*7 + new Integer (this.cod).hashCode();
      ret += ret*7 + (this.name).hashCode();

      return ret;
   }

   public Object clone()
   {
      Client ret = null;

      try
      {
         ret = new Client(this);
      }
      catch(Exception error)
      {
       // this is never null 
      }

      return ret;
   }

   public Client(Client model) throws Exception
   {
      if(model==null)
      throw new Exception("Inexistent model!");

      this.cod = model.cod;
      this.name = model.name;
   }

}

我知道,要发表评论,你必须输入“//”或“/ *”和“* /”。但是如何根据JAVADOC规则发表评论? 如果知道如何,可以使用JAVADOC复制我的代码并将其放入答案中吗?谢谢:) 请告诉我,什么是JAVADOC,它的用途是什么?有没有简单的方法来制作它?

EN

回答 1

Stack Overflow用户

发布于 2018-10-17 13:09:37

Javadoc是在程序中使用的一种注释,用于组织它,使程序更“友好”,并使用评论的所有内容创建页面HTML,如下所示:https//memorynotfound.com/wp-content /uploads/generate-html-javadoc-maven-user.png

因此,要创建一个javadoc,将使用“/ **”代替“/ *”。在创建javadoc时,需要了解各种类型的命令。

@author - 谁创建了程序 @throws - for exceptions @param - 方法参数 @return - 方法返回的内容

所以,使用javadoc的代码将是这样的:

/**
  * @author IncredibleCoding
  */
public class Client
{
protected int cod;
protected String name;

/**
  * instance the code passed
  */
public void setCod(int cod) throws Exception
{
  if(cod==null)
  throw new Exception("Invalid code!");

  this.cod = cod;
}

/**
  * @returns the code
  */
public int getCod()
{
  return this.cod;
}

/**
  * instance the name passed
  * @param name, that is the name passed
  * @throws Exception, if the name is in invalid format
  */
public void setName(String name) throws Exception
{
  if(name==null || name.equals("")
  throw new Exception("Invalid name!");

  this.name = name;
}

/**
  * @returns the name 
  */
public String getName()
{
  return this.name;
}

/**
  * the constructor
  * @param cod, that is the code passed
  * @param name, that is the name passed
  */
public Client(int cod, String name) throws Exception
{
  this.setCod(cod);
  this.setName(name);
}

/**
  * @param obj, that is the object that will be compared
  * @returns true if the object is equal to this, false if the object isn't equal
  */
public boolean equals(Object obj)
{
  if(this==obj)
  return true;

  if(obj==null)
  return false;

  if(!(obj instanceof Client))
  return false;

  Client client = (Client)obj;

  if(this.cod!=client.cod)
  return false;

  if(this.name!=client.name)
  return false;

  return true;
}

/**
  * returns the formatted variable like String
  */
public String toString()
{
  return "Code: " + this.cod + "\n" +
         "Name: " + this.name;
}

/**
  * returns the hashCode of a variable
  */
public int hashCode()
{
  int ret = 444;

  ret += ret*7 + new Integer (this.cod).hashCode();
  ret += ret*7 + (this.name).hashCode();

  return ret;
}

/**
  * clone the object
  */
public Object clone()
{
  Client ret = null;

  try
  {
     ret = new Client(this);
  }
  catch(Exception error)
  {
   // this is never null 
  }

  return ret;
}

/**
  * "copy" the variables
  * @param model, that is the object that will be copied
  * @throws Exception, if the model is inexistent
  */
public Client(Client model) throws Exception
{
  if(model==null)
  throw new Exception("Inexistent model!");

  this.cod = model.cod;
  this.name = model.name;
}

}

你可以看一下这个页面,这对你也有帮助:https//docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100008904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档