tostring

Avoiding recursion in toString method

 ̄綄美尐妖づ 提交于 2021-02-10 16:14:52
问题 this is my huge mindblowing problem with a Java exercise. So, we've got this: public class CyclicEmployee { private int age; private String name; private CyclicEmployee boss; private List<CyclicEmployee> subordinate } and our goal is to overwrite toString method by cutting fields which may lead to recursive infinity. Finally it's supposed to look like a printed object with a name, age, boss and subordinate. Employee[age=30,name='Mike',boss=Employee[age=45,name='Ann'], subordinate=[Employee

Enum.GetName vs Enum.ToString

别等时光非礼了梦想. 提交于 2021-02-08 15:11:23
问题 For this enumeration, Enum MyEnum Value End Enum there are two methods to get the name representation Value of MyEnum.Value : [Enum].GetName(GetType(MyEnum), MyEnum.Value) ' aka Enum.GetName and Dim a As MyEnum = MyEnum.Value a.ToString ' aka Enum.ToString What are their pros and cons? And which is better after all? PS: There is one answer for java but this is .NET which may have different functionality. 回答1: Here are some examples of what can be done using this enum, note the usage of the

Enum.GetName vs Enum.ToString

六眼飞鱼酱① 提交于 2021-02-08 15:10:49
问题 For this enumeration, Enum MyEnum Value End Enum there are two methods to get the name representation Value of MyEnum.Value : [Enum].GetName(GetType(MyEnum), MyEnum.Value) ' aka Enum.GetName and Dim a As MyEnum = MyEnum.Value a.ToString ' aka Enum.ToString What are their pros and cons? And which is better after all? PS: There is one answer for java but this is .NET which may have different functionality. 回答1: Here are some examples of what can be done using this enum, note the usage of the

Django CharField To String

…衆ロ難τιáo~ 提交于 2021-02-07 19:24:29
问题 I'm building a tagging system in Django and would like to allow spaces and other characters in the tag name for display but filter them out and use lower case when matching names etc. To that end I have added a field to my Tag model as so: class Tag(models.Model): name = models.CharField(max_length=200, unique=True) matchname = re.sub("\W+" , "", name.lower()) However I am running into a problem, the CharField is not a string and I cannot for the life of me find out how to convert it to one!

What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names?

蹲街弑〆低调 提交于 2021-02-06 15:20:59
问题 What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names? Long explanation of question follows below. I have determined that this not determined uniquely by any of: alphabetical order; declaration order; nor, name length. For example, consider that I want to have an enum where the numeric values correspond directly to a practical use, (e.g. rgb values for color). public enum RgbColor { Black = 0x000000, Red = 0xff0000, Green =

What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names?

倖福魔咒の 提交于 2021-02-06 15:19:18
问题 What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names? Long explanation of question follows below. I have determined that this not determined uniquely by any of: alphabetical order; declaration order; nor, name length. For example, consider that I want to have an enum where the numeric values correspond directly to a practical use, (e.g. rgb values for color). public enum RgbColor { Black = 0x000000, Red = 0xff0000, Green =

What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names?

半腔热情 提交于 2021-02-06 15:19:12
问题 What determines which name is selected when calling ToString() on an enum value which has multiple corresponding names? Long explanation of question follows below. I have determined that this not determined uniquely by any of: alphabetical order; declaration order; nor, name length. For example, consider that I want to have an enum where the numeric values correspond directly to a practical use, (e.g. rgb values for color). public enum RgbColor { Black = 0x000000, Red = 0xff0000, Green =

Returning a string with toString java

白昼怎懂夜的黑 提交于 2021-01-28 11:10:24
问题 I have been working with a comparable class that runs and compares correctly, but when I try to print the values out, it gives me the memory addresses. I know that this could be fixed with a toString method, but I'm not really sure how to go about doing so. Here's my code: import java.io.*; import java.util.*; import java.lang.Object; public class StreetAddress implements Comparable<StreetAddress> { protected int num; protected String stName; public StreetAddress(int n, String s){ num = n;

MongoDB converts number to string in scientific notation

半城伤御伤魂 提交于 2021-01-28 05:00:20
问题 I want to get full number as a String , but instead "1490650000000" it returns scientific notation "1.49065e+12" Here's how I try to convert it: {$substr: ["$myNumber", 0, -1]}; Any ideas how to prevent it? Note: I'm using v3.6 and can't upgrade to use $toString (thanks mlab). 回答1: If you have mongodb 4.0 then you can use $toLong aggregation db.collection.aggregate([ { "$project": { "myNumber": { "$toLong": "$myNumber" } } } ]) 回答2: You can try as below. db.collectionName.aggregate([ {

How do I write a toString() method [duplicate]

随声附和 提交于 2021-01-28 01:40:34
问题 This question already has answers here : How to override toString() properly in Java? (14 answers) Closed 3 years ago . How would I write a toString() method that prints name and computePay with 2 decimal places for the three employees? The program was working (printing name and weeksPay to command line) before I added the StringBuilder. Any help is appreciated. import javax.swing.JOptionPane; public class TestPayroll { public static void main(String[] args) { Payroll employee1 = new Payroll(