gpt4 book ai didi

java - 在 if 语句中使用 return 有什么作用?

转载 作者:太空狗 更新时间:2023-10-29 22:42:40 25 4
gpt4 key购买 nike

在下面的代码中,if 语句中的 return 有什么作用?

public void startElement(String namespaceURI, String localName,String qName, 
Attributes atts) throws SAXException
{
depth++;
if (localName.equals("channel"))
{
currentstate = 0;
return;
}
if (localName.equals("image"))
{
// record our feed data - you temporarily stored it in the item :)
_feed.setTitle(_item.getTitle());
_feed.setPubDate(_item.getPubDate());
}
if (localName.equals("item"))
{
// create a new item
_item = new RSSItem();
return;
}
if (localName.equals("title"))
{
currentstate = RSS_TITLE;
return;
}
if (localName.equals("description"))
{
currentstate = RSS_DESCRIPTION;
return;
}
if (localName.equals("link"))
{
currentstate = RSS_LINK;
return;
}
if (localName.equals("category"))
{
currentstate = RSS_CATEGORY;
return;
}
if (localName.equals("pubDate"))
{
currentstate = RSS_PUBDATE;
return;
}
// if you don't explicitly handle the element, make sure you don't wind
// up erroneously storing a newline or other bogus data into one of our
// existing elements
currentstate = 0;
}

它是让我们离开 if 语句并继续执行下一个语句,还是让我们离开方法 startElement?

最佳答案

上面代码中的return会让你跳出方法。

关于java - 在 if 语句中使用 return 有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7386728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com