产生inner class对象

博客给出Java代码示例,展示了内外类的定义。介绍了非静态内部类需通过外部类来创建对象,如Parcel11.Contents c = p.new Contents();而静态内部类可直接创建对象,无需借助外部类。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class Parcel11 {
 
class Contents {
 private int i = 11;
 public int value() { return i; }
}
class Destination {
 private String label;
 Destination(String whereTo) {
   label = whereTo;
 }
 String readLabel() { return label; }
}

static class StaticInner{
 String rr="tttt";
}
public static void main(String[] args) {
 Parcel11 p = new Parcel11();
 // Must use instance of outer class
 // to create an instances of the inner class:
 Parcel11.Contents c = p.new Contents();
 Parcel11.Destination d =
   p.new Destination("Tanzania");
 StaticInner staIn=new StaticInner();
 System.out.println(staIn.rr);
}

}

如果是Non-static inner class,需要通过outer class来产生inner class对象,Parcel11.Contents c = p.new Contents();;但是static inner class可以直接产生对象,不用通过outer calss。

for (auto e = boost::edges(sdMap).first; e != boost::edges(sdMap).second; ++e) { auto start = std::chrono::high_resolution_clock::now(); const OsmEdgeProperties &edgeProps = sdMap[*e]; // get vertices geometry LineString linestring_global; std::string line_geometry_string = edgeProps.geometry; if (line_geometry_string.empty()) { boost::adjacency_list<>::vertex_descriptor source = boost::source(*e, sdMap); boost::adjacency_list<>::vertex_descriptor target = boost::target(*e, sdMap); if (source == target) continue; line_geometry_string = "LINESTRING ("; const OsmNodeProperties &startNodeProps = sdMap[*(vertices_pair.first + source)]; line_geometry_string = line_geometry_string + startNodeProps.x + " " + startNodeProps.y + ", "; const OsmNodeProperties &endNodeProps = sdMap[*(vertices_pair.first + target)]; line_geometry_string = line_geometry_string + " " + endNodeProps.x + " " + endNodeProps.y + ")"; } // auto end = std::chrono::high_resolution_clock::now(); boost::geometry::read_wkt(line_geometry_string, linestring_global); // auto end = std::chrono::high_resolution_clock::now(); // auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count(); // std::cout << "sdmap encode timer delay : " << delay << std::endl; // get Properties std::string fclass = edgeProps.fclass; std::vector<std::string> fclass_explode; if (fclass.front() == '[' && fclass.back() == ']') { fclass = fclass.substr(1, fclass.size() - 2); fclass.erase(std::remove_if(fclass.begin(), fclass.end(), ::isspace), fclass.end()); boost::split(fclass_explode, fclass, boost::is_any_of(",")); } else { fclass_explode.push_back(fclass); } for (size_t i = 0; i < fclass_explode.size(); i++) { fclass = "other"; for (const auto &pair : HIGHWAY_SETS) { if (pair.second.find(fclass_explode[i]) != pair.second.end()) { fclass = pair.first; break; } } fclass_explode[i] = fclass; } // transform geometry to local coordinate LineString linestring_local; transformGlobalToEgo(transformationMatrix, linestring_global, linestring_local); std::vector<LineString> inner_lines; // crop try { if (crop) { get_inner_lines(canvas_polygon, linestring_local, inner_lines); } else { inner_lines.push_back(linestring_local); } } catch (const std::exception &e) { std::cerr << "error: " << e.what() << std::endl; continue; } // 将裁剪得到的线段加入结果 for (std::string sub_fclass : fclass_explode) { for (LineString inner_line : inner_lines) { EdgeInfo edge_info{fclass, inner_line}; edges_info.push_back(edge_info); } } } 分析并理解这段代码,发现耗时逐渐递增主要发生在这行段for循环里。
最新发布
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值