Ad
Type 'String' Is Not A Subtype Of Type 'List'
I've got the following code which works well if there are tags present in the widget.tagname
list.
List<String> split = widget.tagname?.split(',')??'';
However, if there are no tags in the list I get this error;
type 'String' is not a subtype of type 'List<String>'
What am I doing wrong?
Ad
Answer
If tagname
is null
, then the compiler attempts to assign the value ''
to a List<String>
, which is not possible. Replace ''
with []
and you should be fine.
Ad
source: stackoverflow.com
Related Questions
- → I can't convert Json to string [OctoberCms]
- → Passing a JS var from AJAX response to Twig
- → how to convert stdclass into string
- → Dynamic url segment name in laravel 5.1
- → Knockout JS - How to return empty strings for observable fields
- → How to replace *( in a string
- → Removing a JavaScript property inside a specific Object within an Array
- → Is this considered to be a custom facade approach in Laravel?
- → JavaScript: How would I reverse ONLY the words in a string
- → How to access a complex object comming from a datatable cell in JQuery/Javascript
- → Regex extract string after the second "." dot character at the end of a string
- → Htaccess negation
- → Convert generic text string in json object into valid url using Angular
Ad